#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,e,g[35][35],u;
bool f[35];

struct node{
	ll l,r;
}a[35];

ll cmp(node a,node b)
{
	if(a.l==b.l)
		return a.r<b.r;
	else 
		return a.l<b.l;
}

void lj()
{
	for(ll i=1;i<=e;i++)
	{
		g[a[i].l][a[i].r]=1;
		g[a[i].r][a[i].l]=1;
	}
}

void dfs(ll u)
{
	if(!f[u])
	{
		cout<<u<<" ";
		f[u]=true;
	}
	for(ll i=1;i<=e;i++)
	{
		if(!f[i] && g[u][i])
			dfs(i);
	}
}

void bfs()
{
	for(ll i=1;i<=e;i++)
    {
    	if(f[a[i].l]==false)
    		cout<<a[i].l<<" ";
    	if(f[a[i].r]==false)
    		cout<<a[i].r<<" ";
    	f[a[i].l]=true;
    	f[a[i].r]=true;
	}
	cout<<endl;
}

int main()
{
    while(cin>>n>>e)
    {
    	for(ll i=1;i<=35;i++)
        {
            for(ll j=1;j<=35;j++)
    			g[i][j]=0;
        }
    	for(ll i=1;i<=e;i++)
    		cin>>a[i].l>>a[i].r;
    	sort(a+1,a+e+1,cmp);
    	lj();
    	memset(f,false,sizeof(f));
    	dfs(1);
    	cout<<endl;
    	memset(f,false,sizeof(f));
    	bfs();
	}
	
    return 0;
}