import sys
from math import cos, radians, pi, sqrt
import numpy as np

head = input().split()
N = int(head[0])
M = int(head[1])
inputs = [input() for i in range(M)]

i = 1
dic = {}
for i in range(0, M):
#	print("探索%d回目" % i)
	param = inputs[i].split()
	A = param[0]
	B = param[1]

	if A in dic.keys():
		dic[A].append(B)
	else:
		dic[A] = []
		dic[A].append(B)

	if B in dic.keys():
		dic[B].append(A)
	else:
		dic[B] = []
		dic[B].append(A)
	
depth = {'1': 0}
que = dic['1']
count=1

while not que == []:
	next_que = []
	for room in que:
		if room in depth.keys():
			continue

		depth[room] = count
		for next_room in dic[str(room)]:
			if not next_room in next_que:
				next_que.append(next_room)
	count += 1
	que = next_que

for i in range(1, N+1):
	for room, dep in depth.items():
		if depth[str(i)]-1 == dep:
			print(room)
			break

#print("Yes")
#for opt in dist.items():
#	print(opt[1])
