#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<vector<int>> G;
int main() {
	cin >> N >> M;
	G.resize(N);
	for (int i = 0; i < M; ++ i) {
		int x, y;
		cin >> x >> y;
		-- x; -- y;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	vector<bool> visited(N);
	deque<int> a;
	a.push_back(0); visited[0] = true;
	a.push_back(G[0][0]); visited[G[0][0]] = true;
	for (;;) {
		int x = a.back();
		for (auto y : G[x]) if (!visited[y]) {
			a.push_back(y); visited[y] = true;
			goto next1;
		}
		break;
		next1:;
	}
	for (;;) {
		int x = a.front();
		for (auto y : G[x]) if (!visited[y]) {
			a.push_front(y); visited[y] = true;
			goto next2;
		}
		break;
		next2:;
	}

	cout << a.size() << endl;
	for (auto x : a) cout << x+1 << " ";
	cout << endl;
}
