def func():
def bfs(node):
Q = [ 0 ] * ( nodes + 1 )
first = 0
last = 0
explored = [0] * (nodes+1)
Q[first] = node
explored[node] = 1
while first <= last:
vertex = Q[first]
k = 0
while k < nodes+1:
if matrix[vertex][k] == 1 and explored[k] == 0:
explored[k] = 1
last+=1
Q[last] = k
k+=1
first+=1
for i in range(0, nodes):
print(Q[i], end=" ")
line = input().split(" ")
nodes = int(line[0])
edges = int(line[1])
matrix = [[0 for column in range(nodes+1)] for row in range(nodes+1)]
for k in range(0, edges):
line = [int(i) for i in input().split(" ")]
x = int(line[0])
y = int(line[1])
matrix[x][y] = 1
startNode = 1
bfs(startNode)
func()
ZGVmIGZ1bmMoKToKCiAgICBkZWYgYmZzKG5vZGUpOgogICAgICAgIFEgPSBbIDAgXSAqICggbm9kZXMgKyAxICkKICAgICAgICBmaXJzdCA9IDAKICAgICAgICBsYXN0ID0gMAogICAgICAgIGV4cGxvcmVkID0gWzBdICogKG5vZGVzKzEpCiAgICAgICAgUVtmaXJzdF0gPSBub2RlCiAgICAgICAgZXhwbG9yZWRbbm9kZV0gPSAxCgogICAgICAgIHdoaWxlIGZpcnN0IDw9IGxhc3Q6CiAgICAgICAgICAgIHZlcnRleCA9IFFbZmlyc3RdCiAgICAgICAgICAgIGsgPSAwCiAgICAgICAgICAgIHdoaWxlIGsgPCBub2RlcysxOgogICAgICAgICAgICAgICAgaWYgbWF0cml4W3ZlcnRleF1ba10gPT0gMSBhbmQgZXhwbG9yZWRba10gPT0gMDoKICAgICAgICAgICAgICAgICAgZXhwbG9yZWRba10gPSAxCiAgICAgICAgICAgICAgICAgIGxhc3QrPTEKICAgICAgICAgICAgICAgICAgUVtsYXN0XSA9IGsKICAgICAgICAgICAgICAgIGsrPTEKICAgICAgICAgICAgZmlyc3QrPTEKCiAgICAgICAgZm9yIGkgaW4gcmFuZ2UoMCwgbm9kZXMpOgogICAgICAgICAgICBwcmludChRW2ldLCBlbmQ9IiAiKQoKICAgIGxpbmUgPSBpbnB1dCgpLnNwbGl0KCIgIikKICAgIG5vZGVzID0gaW50KGxpbmVbMF0pCiAgICBlZGdlcyA9IGludChsaW5lWzFdKQogICAgbWF0cml4ID0gW1swIGZvciBjb2x1bW4gaW4gcmFuZ2Uobm9kZXMrMSldIGZvciByb3cgaW4gcmFuZ2Uobm9kZXMrMSldCiAgICBmb3IgayBpbiByYW5nZSgwLCBlZGdlcyk6CiAgICAgICBsaW5lID0gW2ludChpKSBmb3IgaSBpbiBpbnB1dCgpLnNwbGl0KCIgIildCiAgICAgICB4ID0gaW50KGxpbmVbMF0pCiAgICAgICB5ID0gaW50KGxpbmVbMV0pCiAgICAgICBtYXRyaXhbeF1beV0gPSAxCiAgICAKICAgIHN0YXJ0Tm9kZSA9IDEKICAgIGJmcyhzdGFydE5vZGUpCmZ1bmMoKQ==