#include<bits/stdc++.h>
#define maxn 100005
using namespace std;
int n,m;
vector<int>p[maxn];
vector<int>v[maxn];
queue<int>q;
bool u[maxn],w[maxn];
void solve(int x);
int main(){
cin >> n >> m;
for(int i = 1;i <= m;i++){
int x,y;
cin >> x >> y;
p[x].push_back(y);
v[x].push_back(y);
}
u[1] = true;
solve(1);
cout << endl;
w[1] = true;
q.push(1);
while(!q.empty()){
int x = q.front();
q.pop();
cout << x << " ";
for(int i = 0,sz = v[x].size();i < sz;i++){
if(!w[v[x][i]]){
w[v[x][i]] = true;
q.push(v[x][i]);
}
}
}
return 0;
}
void solve(int x){
cout << x << " ";
for(int i = 0,sz = p[x].size();i < sz;i++){
if(!u[p[x][i]]){
u[p[x][i]] = true;
solve(p[x][i]);
}
}
}