Lunar New Year is approaching, and Bob decides to take a wander in a nearby park.

The park can be represented as a connected graph with $n$ nodes and $m$ bidirectional edges. Initially Bob is at the node $1$ and he records $1$ on his notebook. He can wander from one node to another through those bidirectional edges. Whenever he visits a node not recorded on his notebook, he records it. After he visits all nodes at least once, he stops wandering, thus finally a permutation of nodes $a_1, a_2, \ldots, a_n$ is recorded.

Wandering is a boring thing, but solving problems is fascinating. Bob wants to know the lexicographically smallest sequence of nodes he can record while wandering. Bob thinks this problem is trivial, and he wants you to solve it.

A sequence $x$ is lexicographically smaller than a sequence $y$ if and only if one of the following holds:   $x$ is a prefix of $y$, but $x \ne y$ (this is impossible in this problem as all considered sequences have the same length);  in the first position where $x$ and $y$ differ, the sequence $x$ has a smaller element than the corresponding element in $y$. 


-----Input-----

The first line contains two positive integers $n$ and $m$ ($1 \leq n, m \leq 10^5$), denoting the number of nodes and edges, respectively.

The following $m$ lines describe the bidirectional edges in the graph. The $i$-th of these lines contains two integers $u_i$ and $v_i$ ($1 \leq u_i, v_i \leq n$), representing the nodes the $i$-th edge connects.

Note that the graph can have multiple edges connecting the same two nodes and self-loops. It is guaranteed that the graph is connected.


-----Output-----

Output a line containing the lexicographically smallest sequence $a_1, a_2, \ldots, a_n$ Bob can record.


-----Examples-----
Input
3 2
1 2
1 3

Output
1 2 3 

Input
5 5
1 4
3 4
5 4
3 2
1 5

Output
1 4 3 2 5 

Input
10 10
1 4
6 8
2 5
3 7
9 4
5 6
3 4
8 10
8 9
1 10

Output
1 4 3 7 9 8 6 5 2 10 



-----Note-----

In the first sample, Bob's optimal wandering path could be $1 \rightarrow 2 \rightarrow 1 \rightarrow 3$. Therefore, Bob will obtain the sequence $\{1, 2, 3\}$, which is the lexicographically smallest one.

In the second sample, Bob's optimal wandering path could be $1 \rightarrow 4 \rightarrow 3 \rightarrow 2 \rightarrow 3 \rightarrow 4 \rightarrow 1 \rightarrow 5$. Therefore, Bob will obtain the sequence $\{1, 4, 3, 2, 5\}$, which is the lexicographically smallest one.

Difficulty: interview

Starter code:

Solutions:
from heapq import *
n, m = map(int, input().split())
g = {}
for _ in range(m):
    u, v = map(int, input().split())
    g.setdefault(u, set()).add(v)
    g.setdefault(v, set()).add(u)

d = []
V = set()
h = [1]
while h:
    v = heappop(h)
    if v in V:
        continue
    V.add(v)
    d.append(v)
    for u in g[v]:
        heappush(h, u)
print(*d)

from heapq import heapify, heappush, heappop


def solve():
    n, m = [int(x) for x in input().split()]

    adjs = [[] for _ in range(n)]
    for _ in range(m):
        a, b = [int(x) for x in input().split()]
        a -= 1
        b -= 1
        adjs[a].append(b)
        adjs[b].append(a)

    seq = [1]
    visited = set([0])
    frontier = adjs[0].copy()
    heapify(frontier)

    while frontier:
        node = heappop(frontier)
        if node in visited:
            continue

        seq.append(node+1)
        visited.add(node)
        for neighbor in adjs[node]:
            if neighbor not in visited:
                heappush(frontier, neighbor)

    print(*seq)


solve()


def ii():
    return int(input())
def mi():
    return list(map(int, input().split()))
def li():
    return list(mi())
import heapq

n, m = mi()
g = [[] for i in range(n + 1)]
for i in range(m):
    u, v = mi()
    g[u].append(v)
    g[v].append(u)

vis = [0] * (n + 1)
vis[1] = 1
pq = [1]
ans = []
while pq:
    u = heapq.heappop(pq)
    ans.append(u)
    for v in g[u]:
        if not vis[v]:
            heapq.heappush(pq, v)
            vis[v] = 1

print(*ans)


from collections import defaultdict
import heapq
graph = defaultdict(set)
n,m = map(int,input().split())
for _ in range(m):
    a,b = map(int,input().split())
    if a!=b:
        graph[a].add(b)
        graph[b].add(a)

seen = {1}
hist = [1]
h = list(graph[1])
heapq.heapify(h)
while len(hist)<n:
    next_node = heapq.heappop(h)
    if next_node in seen:continue
    seen.add(next_node)
    hist.append(next_node)
    for node in graph[next_node]:
        heapq.heappush(h,node)
print (" ".join(str(x) for x in hist))

from heapq import *

n, m = list(map(int, input().split()))
vis = [0, 1] + [0] * (n - 1)
e = [[] for i in range(n + 1)]
for i in range(m):
	u, v = list(map(int, input().split()))
	e[u].append(v)
	e[v].append(u)
ans = []
h = [1]
while h:
	cur = heappop(h)
	ans.append(cur)
	for to in e[cur]:
		if not vis[to]:
			vis[to] = 1
			heappush(h, to)
print(*ans)



from heapq import heappop, heappush

n, m = list(map(int, input().split()))
a = []
as_ = set()
g = [set() for _ in range(n + 2)]
for _2 in range(m):
    u, v = list(map(int, input().split()))
    g[u].add(v)
    g[v].add(u)
h = [1]
while h:
    u = heappop(h)
    if u not in as_:
        a.append(u)
        as_.add(u)
        for v in g[u]:
            heappush(h, v)
print(*a)


import queue

def __starting_point():
    n, m = list(map(int, input().split()))
    g = [set() for _ in range(n)]
    for i in range(m):
        a, b = list(map(int, input().split()))
        g[a - 1].add(b - 1)
        g[b - 1].add(a - 1)

    q = queue.PriorityQueue()
    q.put(0)

    visited = set()
    sq = []
    while len(visited) != n:
        node = q.get()
        if node not in visited:
            visited.add(node)
            sq.append(node)
        else:
            continue

        for nxt in g[node]:
            q.put(nxt)

    print(" ".join(list([str(x + 1) for x in sq])))

__starting_point()

# -*- coding: utf-8 -*-
# @Time    : 2019/1/31 21:44
# @Author  : LunaFire
# @Email   : gilgemesh2012@gmail.com
# @File    : D. Lunar New Year and a Wander.py

import heapq


def main():
    n, m = list(map(int, input().split()))
    graph_dict = {}
    for _ in range(m):
        u, v = list(map(int, input().split()))
        temp_list = graph_dict.get(u, [])
        temp_list.append(v)
        graph_dict[u] = temp_list
        temp_list = graph_dict.get(v, [])
        temp_list.append(u)
        graph_dict[v] = temp_list

    visit = [False] * (n + 1)
    h, ret = [], []
    heapq.heappush(h, 1)
    while h:
        u = heapq.heappop(h)
        if visit[u]:
            continue
        ret.append(u)
        visit[u] = True
        for v in graph_dict.get(u, []):
            if visit[v]:
                continue
            heapq.heappush(h, v)
    print(*ret)


def __starting_point():
    main()

__starting_point()

import heapq 
from collections import defaultdict
d=defaultdict(list)
n,m=map(int,input().split())
for i in range(m):
    a,b=map(int,input().split())
    a=a-1 
    b=b-1 
    d[a].append(b)
    d[b].append(a)
vis=[0]*n 
vis[0]=1 
print(1,end=' ')
l=[]
for i in d[0]:
    if not vis[i]:
        heapq.heappush(l,i)
        vis[i]=1 
heapq.heapify(l)
while l:
    t=heapq.heappop(l)
    print(t+1,end=' ')
    for i in d[t]:
        if not vis[i]:
            heapq.heappush(l,i)
            vis[i]=1 

from heapq import heappop, heappush
import sys
N, M = map(int, input().split())
edges = [[] for _ in [0]*N]
for u, v in (map(int, l.split()) for l in sys.stdin):
    edges[u-1].append(v-1)
    edges[v-1].append(u-1)

visited = [0]*N
ans = []
heap = [0]
ans_append = ans.append

while heap:
    v = heappop(heap)
    visited[v] = 1
    ans_append(v+1)

    edges[v].sort()
    for to_v in edges[v]:
        if visited[to_v]:
            continue
        visited[to_v] = 1
        heappush(heap, to_v)

print(*ans)

import sys
import heapq
#sys.setrecursionlimit(200000)
input = sys.stdin.readline
n,m = map(int,input().split())
g = [[] for i in range(n)]
for i in range(m):
        a,b = map(int,input().split())
        a-=1;b-=1
        g[a].append(b)
        g[b].append(a)
que = [0]
heapq.heapify(que)
ans = []
used = [0]*n
for i in range(n):
        a = heapq.heappop(que)
        while used[a] == 1:
             a = heapq.heappop(que)   
        used[a] = 1
        ans.append(a+1)
        for j in g[a]:
                if used[j] == 0:
                        heapq.heappush(que,j)
print(*ans)

import sys
import heapq
input = sys.stdin.readline

n,m=map(int,input().split())
EDGE=[list(map(int,input().split())) for i in range(m)]

EDGELIST=[[] for i in range(n+1)]

for x,y in EDGE:
    EDGELIST[x].append(y)
    EDGELIST[y].append(x)

NOW=EDGELIST[1]
heapq.heapify(NOW)

check=[0]*(n+1)
ANS=[1]
check[1]=1
while NOW:
    x=heapq.heappop(NOW)
    if check[x]==1:
        continue
    else:
        ANS.append(x)
        check[x]=1
        for e in EDGELIST[x]:
            if check[e]==0:
                heapq.heappush(NOW,e)

for a in ANS:
    print(a,end=" ")

        


from collections import defaultdict
import heapq
def inpl(): return list(map(int, input().split()))
N, M = inpl()
Edge = defaultdict(lambda: [])
for _ in range(M):
    a, b = inpl()
    if a != b:
        Edge[a].append(b)
        Edge[b].append(a)
Ans = [] 
visited = set([1])
Candi = [1]
for _ in range(N):
    j = heapq.heappop(Candi)
    for k in Edge[j]:
        if k not in visited:
            visited.add(k)
            heapq.heappush(Candi, k)
    Ans.append(j)
print(*Ans)

import bisect

def dfs(i,vis,g):
	print(i,end=" ")
	vis[i]=1
	for j in g[i]:
		if vis[j]==0:
			dfs(j,vis,g)

n,m=map(int,input().split())
g=[[] for i in range(n+1)]
for i in range(m):
	u,v=map(int,input().split())
	bisect.insort(g[u],v)
	bisect.insort(g[v],u)
bfs=[1]
l=1
vis=[0]*(n+1)
vis[1]=1
while l!=0:
	i=bfs.pop(0)
	print(i,end=" ")
	l-=1
	for j in g[i]:
		if vis[j]==0:
			bisect.insort(bfs,j)
			vis[j]=1
			l+=1

#dfs(1,vis,g)
print()


from heapq import heappush, heappop, heapify
class MinHeap:
    def __init__(self):
        self.heap = []

    def parent(self, i):
        return (i - 1) / 2
    def insertKey(self, k):
        heappush(self.heap, k)

    def extractMin(self):
        return heappop(self.heap)

heapObj = MinHeap()



from collections import defaultdict

graph = defaultdict(list)
n,m = map(int,input().split())
for i in range(m):
    u, v = map(int, input().split())
    graph[u-1].append(v-1)
    graph[v-1].append(u-1)
visited = [False] * (n)
# queue = []
heapObj.insertKey(0)
visited[0] = True
count = 0
while count !=n:
    s = heapObj.extractMin()
    print (s+1, end = " ")
    for i in graph[s]:
        if visited[i] == False:
            heapObj.insertKey(i)
            visited[i] = True
    count+=1
print()

import heapq
n, m = map(int, input().split())
vertexs = dict()
for i in range(1, n+1):
    vertexs[i] = []

for j in range(m):
    v, u = map(int, input().split())
    if v != u:
        vertexs[v].append(u)
        vertexs[u].append(v)

vis = dict()
dp = [1]
vis[1] = True

answers = []
for i in range(n):
    next_v = heapq.heappop(dp)
    answers.append(next_v)
    vis[next_v] = True

    for u in vertexs[next_v]:
        if u not in vis:
            heapq.heappush(dp, u)
            vis[u] = True

print(*answers, sep=' ')

from collections import defaultdict, deque
from bisect import insort
n, m = map(int, input().split())
d = defaultdict(list)
visited = [False]*(n+1)
for _ in range(m):
    u, v = map(int, input().split())
    insort(d[u], v)
    insort(d[v], u)
z = deque([1])
visited[1] = True
while z:
    front = z.popleft()
    print(front, end = ' ')
    for i in d[front]:
        if not visited[i]:
            insort(z, i)
            visited[i] = True

from heapq import *

n , m = list(map( int , input().split() ))
graph = {}

for _ in range(m):
    a , b = list(map( int , input().split() ))
    graph.setdefault(a, set()).add(b)
    graph.setdefault(b, set()).add(a)

ans = []
visited = set()
heap = [1]

while heap:
    v = heappop(heap)
    if v in visited:
        continue
    visited.add(v)
    ans.append(v)
    for neighbour in graph[v]:
        heappush(heap, neighbour)

print(*ans)



import sys
import collections
import heapq

data = sys.stdin.read().splitlines()

n, m = list(map(int, data[0].split()))
graph = collections.defaultdict(set)

for line in data[1:]:
    a, b = list(map(int, line.split()))
    graph[a].add(b)
    graph[b].add(a)

for node in graph:
    graph[node] = sorted(graph[node], reverse=True)


visited = [False] * (n + 1)
visited[1] = True
ans = []
queue = [1]

while True:
    cur = heapq.heappop(queue)
    ans.append(cur)
    if len(ans) == n:
        break
    for nei in graph[cur]:
        if not visited[nei]:
            visited[nei] = True
            heapq.heappush(queue, nei)

print(' '.join(map(str, ans)))


import heapq,sys
def __starting_point():
    path = dict()
    input()
    for line in sys.stdin:
        if line.strip() == '':
            break
        n,m = [int(i) for i in line.strip().split()]
        if n not in path:
            path[n] = [m]
        else:
            path[n].append(m)
        if m not in path:
            path[m] = [n]
        else:
            path[m].append(n)
    ans = [1]
    visited = set([1])
    pq = path[1]
    heapq.heapify(pq)
    while len(pq) > 0:
        the_next = heapq.heappop(pq)
        if the_next not in visited:
            ans.append(the_next)
            visited.add(the_next)
            for i in path[the_next]:
                heapq.heappush(pq,i)
    print(' '.join([str(i) for i in ans]))
            

__starting_point()