NodeNum, EdgeNum = map(int, input().split())
MyMap = [[0] * (NodeNum+1) for _ in range(NodeNum+1)]
visited = [0] * (NodeNum+1)
stack = []
for _ in range(EdgeNum):
row, col = map(int, input().split())
MyMap[row][col] = 1
MyMap[col][row] = 1
def findNext(here):
for next in range(NodeNum+1):
if MyMap[here][next] and not visited[next]:
return next
def DFS(here):
print(here,end=' ')
visited[here] = True
while here:
next = findNext(here)
if next: # 다음으로 갈 node가 있다면
stack.append(here) # 돌아올 부모 노드 저장
while next:
here = next
print(here,end=' ')
visited[here] = True
next = findNext(here)
if next:
stack.append(here)
if len(stack) != 0:
here = stack.pop()
else:
here = False
DFS(1)
# 방문 순서
# 1 2 6 5 7 3 4
재귀로 DFS
import sys
sys.stdin = open("input.txt", 'r')
NodeNum, EdgeNum = map(int, input().split())
MyMap = [[0] * (NodeNum+1) for _ in range(NodeNum+1)]
visited = [0] * (NodeNum+1)
for _ in range(EdgeNum):
row, col = map(int, input().split())
MyMap[row][col] = 1
MyMap[col][row] = 1
for row in range(1, len(MyMap)):
for col in range(1, len(MyMap[0])):
print(MyMap[row][col], end='')
print()
# MyMap
# 0111100
# 1000011
# 1000000
# 1000000
# 1000010
# 0100101
# 0100010
def DFS(here):
print(here, end=' ')
visited[here] = True
for next in range(1, NodeNum+1):
if MyMap[here][next] and not visited[next]:
DFS(next)
DFS(1)