#include <bits/stdc++.h>
using namespace std;
const int N = 100010,M = 1000010;
int ne[M],e[M],h[N],t[N],idx;
bool st[N];
int n,m;
// void add(int a,int b) {
// e[idx] = b;
// ne[idx] = h[a];
// h[a] = idx++;
// }
void add_tail(int a,int b) {
e[idx] = b;
ne[idx] = -1;
if(h[a] == -1) {
h[a] = idx;
}else {
ne[t[a]] = idx;
}
t[a] = idx++;
}
void dfs(int u) {
st[u] = 1;
cout << u << " ";
for(int i = h[u];i != -1;i = ne[i]) {
int j = e[i];
if(!st[j]) dfs(j);
}
}
void bfs() {
queue<int> q;
q.push(1);
cout << 1 << " ";
while(q.size()) {
int fr = q.front();
q.pop();
for(int i = h[fr];i != -1;i = ne[i]) {
int j = e[i];
if(!st[j]) {
cout << j << " ";
st[j] = 1;
q.push(j);
}
}
}
}
int main(){
memset(h,-1,sizeof(h));
cin >> n >> m;
while(m--) {
int a,b;
cin >> a >> b;
add_tail(a,b);
}
dfs(1);
cout << endl;
memset(st,0,sizeof(st));
bfs();
cout << endl;
return 0;
}