#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;


int N, M;
vector<vector<int>> adj;

vector<int> vis, path;

void dfs(int at) {
	for (int c : adj[at]) if (!vis[c]) {
		vis[c] = 1;
		path.push_back(c);
		dfs(c);
		return;
	}
}

int main() {
	cin >> N >> M;
	adj.resize(N);
	for (int i = 0; i < M; ++i) {
		int u, v;
		cin >> u >> v;
		--u; --v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	vis.resize(N);
	path.push_back(0);
	vis[0] = 1;
	dfs(0);
	reverse(path.begin(), path.end());
	dfs(0);
	cout << path.size() << endl;
	for (int p : path) {
		cout << p+1 << " ";
	}
	cout << endl;
	cin >> ws;
}