from collections import deque
# 방문 리스트
visited = [False]*(N+1)
# 인접 리스트 생성
# N : 총 노드 개수 / s,e : 노드1, 노드2
A = [[] for _ in range(N+1)]
for_in range(N):
s,e= map(int,input().split())
A[s].append(e)
A[e].append(s)
# 인접 리스트 정렬
for i in range(N+1):
A[i].sort()
def BFS(v):
queue = deque()
# 큐에 시작 노드 삽입
queue.append(v)
while queue:
# 노드 꺼내기(선입선출)
now_Node = queue.popleft()
# 탐색 순서대로 출력
print(now_Node,end = ' ')
# 꺼낸 노드의 인접 노드 중 이미 방문한 것 제외하고 큐에 넣기
for i in A[now_Node]:
if not visited[i]:
# 방문 리스트 체크
visited[i] = True
queue.append(i)
# start : 시작 노드
BFS(start)