#include<bits/stdc++.h>
using namespace std;
const int N= 1e5;
bool b[N];
struct node{
int bh;
vector<int>z;
void paixu(){
sort(z.begin(),z.end());
}
}a[100000];
void dfs (int root){
cout<<root<<" ";
b[root]=1;
a[root].paixu();
for(int k:a[root].z){
if(!b[k]){
dfs(k);
}
}
}
int main(){
int n,m;
cin>>n>>m;
memset(b,'0',sizeof(b));
int fa,ch;
for(int i=1;i<=m;++i){
cin>>fa>>ch;
a[fa].bh=fa;a[fa].z.push_back(ch);
}
dfs(1);
memset(b,'0',sizeof(b));
cout<<endl;
queue<int> qu;
qu.push(1);
while(!qu.empty()){
int t=qu.front();
qu.pop();
if(!b[t]){
cout<<t<<" ";
b[t]=1;
a[t].paixu();
for(int k:a[t].z){
qu.push(k);
}
}
}
}
各位大佬麻烦帮我看一下,说是第一行太短