/************************************
 *  Event  :      Interuni 2009, Vologda
 *  Problem:      Cycle
 *  Author:       Pavel Kuznetsov
 *  Last update:  2000.02.23 15:38
 ************************************
*/

#include <map> 
#include <set> 
#include <queue> 
#include <bitset> 
#include <valarray> 
#include <complex> 
#include <iostream> 
#include <stdio.h>
#include <sstream> 
#include <cmath> 
#include <algorithm> 
#include <string> 
#include <cassert> 

#pragma comment(linker,"/STACK:20000000")

using namespace std;

// prewritten code

#define Size(x) (int)(x).size()
#define For(i,a,b) for(int i=(int)(a);i<=(int)(b);++i)
#define Ford(i,a,b) for(int i=(int)(a);i>=(int)(b);--i) 
#define RepV(i,v) for (int i=0;i<Size(v);++i)
#define All(c) (c).begin(),(c).end()
#define Fill(a,b) memset(&a,b,sizeof(a))
#define Min(a,b) ((a)<(b)?(a):(b))
#define Max(a,b) ((a)>(b)?(a):(b))
#define Abs(a) ((a)<0?-(a):(a))
#define VVI vector<vector<int> >
#define VI vector<int>
#define VVS vector<vector<string> >
#define VS vector<string>
#define ForEach(it,a) for (typeof((a).begin()) it=(a).begin(); it!=(a).end(); ++it)
#define DBG(x) cout << #x <<" = "<< x << endl;
#define DBGA(x) {cout << #x <<": "; for (int i=0; i<(int)sizeof(x)/(int)sizeof(x[0]); ++i) cout<<x[i]<<' '; cout<<endl;}
#define DBGV(x) {cout << #x <<": "; for (int i=0; i<(int)Size(x); ++i) cout<<x[i]<<' '; cout<<endl;}

const string problem_name = "cycle";

const int MINN = 1;
const int MAXN = 100000;

int n, m, prev[MAXN+1], cnt[MAXN+1], was[MAXN+1];
VI mate[MAXN+1];
bool found;

void dfs(int u, int z, int from){
	if (found) return;
	was[u]=z;
	RepV(i,mate[u]) if (mate[u][i]!=from) if (was[mate[u][i]] != z) {
		if (found) return;
		prev[mate[u][i]]=u;
		dfs(mate[u][i],z,u);
	} else {
		if (found) return;
		found=true;
		
		int t=mate[u][i];
		printf("%d ",t);
		while (1) {
			printf("%d ",u);
			if (u==t) break;
			u=prev[u];
		};
		
		return;
	}
	was[u]=0;
}

int main(){
//	freopen((problem_name+".in").c_str(),"rt",stdin);
//	freopen((problem_name+".out").c_str(),"wt",stdout);
	
	scanf("%d%d",&n,&m);
	
	assert( MINN <= n && n <= MAXN);
	assert( 2*n <= m && m <= 3*n );
	
	int cmp = n;
	
	For(i,1,m) {
		int x, y;
		scanf("%d%d",&x,&y);
		
		assert( 1 <= x && x <= n );
		assert( 1 <= y && y <= n );
		
		if (x == y) {
			printf("%d %d",x,y);
			return 0;
		}
		
		mate[x].push_back(y);
		mate[y].push_back(x);
		++cnt[x]; ++cnt[y];
	}
	
	vector<pair<int,int> > v;
	For(i,1,n) v.push_back(make_pair(cnt[i],i));
	
	int z=0;
	sort(All(v));
	found=false;
	Ford(i,n-1,0) {
		prev[v[i].second]=-1;
		dfs(v[i].second,++z,-1);
		if (found) break;
	}
	
	return 0;
}
