#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
const int N = 10010;
struct Node{
int id;
Node *next;
Node(int _id): id(_id), next(NULL){}
}* head[N];
bool read[N];
void add(int x, int y)
{
auto p = new Node(y);
p->next = head[x];
head[x] = p;
}
/*void dfs(int t)
{
read[t] = true;
cout << t << " ";
for(auto p=head[t]; p; p=p->next)
{
int o=p->id;
if(!read[o]) dfs(o);
}
}
*/
void bfs(){
queue<int> q;
q.push(1);
read[1] = true;
while(q.size()){
auto o = q.front();
q.pop();
cout << o << " ";
for(auto p=head[o]; p; p=p->next)
{
int j = p->id;
if(!read[j])
{
read[j] = true;
q.push(j);
}
}
}
}
int main()
{
int n, m;
cin >> n >> m;
while(m--)
{
int x, y;
cin >> x >> y;
add(x,y);
}
/* for(int i=1; i<=n; i++)
{
if(!read[i]) dfs(i);
}
*/
bfs();
return 0;
}
```