//广度优先搜索树,一定要使用队列,队列的特性很好用
import java.util.*;
public class Guangduyouxiansousuosuanfa1 {
public static void main(String args[]){
Scanner in=new Scanner(System.in);
while(in.hasNext()){
int V=in.nextInt();
int E=in.nextInt();
List graph[]=new ArrayList[V+1];
for(int i=0;i<=V;i++)
graph[i]=new ArrayList();
for(int i=0;i();
Queue tempq=new LinkedList<>();
int visit[]=new int[V+1];
//这里默认从图1节点开始广度优先遍历
ans.offer(1);
tempq.offer(1);
visit[1]=1;
while(tempq.size()>0){
int temp0=(int)tempq.poll();
for(int i=0;i0){
if(flag2==1){
System.out.print(ans.poll());
flag2=0;
}else{
System.out.print(" "+ans.poll());
}
}
System.out.println();
}
}
}