import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

void main(){
	int n = read.to!int;
	int m = read.to!int;
	
	bool[int] isUsed;
	for(int i = 1; i <= n; i ++) isUsed[i] = 0;
	
	debug isUsed.writeln;
	
	int a, b;
	bool[int][int] adjset;
	for(int i = 0; i < m; i ++){
		a = read.to!int;
		b = read.to!int;
		adjset[a][b] = 1;
		adjset[b][a] = 1;
		}
	
	int a0 = a;
	isUsed[a] = 1;
	
	int[] ans1 = [];
	while(1){
		int[] bs = adjset[a].keys;
		debug writeln(a, " ", bs, " ", isUsed);
		bool foundflag = 0;
		foreach(b1; bs){
			if(!isUsed[b1]){
				b = b1;
				debug writeln(b);
				foundflag = 1;
				break;
				}
			}
		if(!foundflag) break;
		else{
			isUsed[b] = 1;
			ans1 ~= b;
			a = b;
			}
		}
	
	debug writeln("-");
	
	a = a0;
	int[] ans2 = [];
	while(1){
		int[] bs = adjset[a].keys;
		debug writeln(a, " ", bs, " ", isUsed);
		bool foundflag = 0;
		foreach(b1; bs){
			if(!isUsed[b1]){
				b = b1;
				debug writeln(b);
				foundflag = 1;
				break;
				}
			}
		if(!foundflag) break;
		else{
			isUsed[b] = 1;
			ans2~= b;
			a = b;
			}
		}
	
	(ans1.reverse ~ [a0] ~ ans2).map!(to!string).join(" ").writeln;
	} 