import java.io.*;
import java.util.*;

public class doggy_av {

	FastScanner in;
	PrintWriter out;
	final String fileName = "doggy".toLowerCase();
	
	void solve() {
		int n = in.nextInt();
		int m = in.nextInt();
		List<Integer>[] graph = new List[n];
		readGraph(n, m, graph);
		List<Integer> ans = goDfs(graph);		
		out.println(ans.size());
		for (int i : ans) {
			out.print((i + 1) + " ");
		}
		out.println();
	}

	private List<Integer> goDfs(final List<Integer>[] graph) {
		final int n = graph.length;
		
		class DFSActor {
			final boolean[] used = new boolean[n];
			final int[] depth = new int[n];
			
			final int[] result = new int[n];
			final int[] stack, pos;
			
			int bestLen; 
			int sp;
			
			public DFSActor() {
				stack = new int[n];
				pos = new int[n];
				sp = 0;
			}
			
			private void dfs(int u, int parent, int d) {
				used[u] = true;
				depth[u] = d;
				stack[sp++] = u;
				pos[u] = sp - 1;
				for (int i = 0; i < graph[u].size(); i++) {
					int v = graph[u].get(i);
					if (!used[v]) {
						dfs(v, u, d + 1);
					} else {
						if (v == parent) {
							continue;
						}
						int cycleLen = pos[u] - pos[v] + 1;
						if (cycleLen > bestLen) {
							bestLen = cycleLen;
							System.arraycopy(stack, pos[v], result, 0, cycleLen);
						}
					}
				}
				sp--;
				used[u] = false;
			}
			
			public void startDFS() {
				dfs(0, -1, 0);
			}
		}
		
		DFSActor actor = new DFSActor();
		actor.startDFS();
		List<Integer> ans = new ArrayList<Integer>(actor.bestLen);
		for (int i = 0; i < actor.bestLen; i++) {
			ans.add(actor.result[i]);
		}
		return ans;
	}

	private void readGraph(int n, int m, List<Integer>[] graph) {
		for (int i = 0; i < n; i++) {
			graph[i] = new ArrayList<Integer>();
		}
		
		for (int i = 0; i < m; i++) {
			int a = in.nextInt() - 1;
			int b = in.nextInt() - 1;
			graph[a].add(b);
			graph[b].add(a);
		}
	}

	void run() {
		try {
			in = new FastScanner(fileName + ".in");
			out = new PrintWriter(fileName + ".out");
			solve();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}

	public static void main(String[] args) {
		new doggy_av().run();
	}
}
