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

#include <map> 
#include <stdio.h>
#include <string.h>
#include <set> 
#include <queue> 
#include <bitset> 
#include <valarray> 
#include <complex> 
#include <iostream> 
#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, p[MAXN+1], r[MAXN+1], prev[MAXN+1];
vector<pair<int,int> > edges;
vector<int> mate[MAXN+1];
queue<int> q;

int getp(int u){
	if (p[u] != u) p[u] = getp(p[u]);
	return p[u];
}

bool merge(int u, int v){
	int pu=getp(u), pv=getp(v);
	if (pu == pv) return false;
	
	if (r[pu] > r[pv]){
		p[pv] = pu;
	} else {
		p[pu] = pv;
		if (r[pu] == r[pv]) ++r[pv];
	}
	
	return true;
}

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 );
	
	For(i,1,n) p[i]=i, r[i]=1;
	
	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;
		}
		
		if (!merge(x,y)) edges.push_back(make_pair(x,y));
		else --cmp;
	}
	
	assert( cmp == 1 );
	assert( Size(edges) > n-1 );
	
	For(i,1,n) p[i]=i, r[i]=1;
	
	RepV(i,edges) {
		int x = edges[i].first, y = edges[i].second;
		if (merge(x,y)) {
			mate[x].push_back(y);
			mate[y].push_back(x);
		} else {
			q.push(x);
			prev[x] = -1;
			
			while (!q.empty()){
				int cur=q.front(); q.pop();
				if (cur == y) break;
				RepV(j,mate[cur]) if (!prev[mate[cur][j]]) {
					prev[mate[cur][j]] = cur;
					q.push(mate[cur][j]);
				}
			}
			
			int last=y;
			assert(prev[y]);
			
			while (y != -1){
				printf("%d ",y);
				y=prev[y];
			}
			
			printf("%d",last);
			return 0;
		}
	}
	
	assert(false);
	
	return 0;
}
