#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1<<17;

bool bio[MAXN];
vector<int> edges[MAXN];
deque<int> sol;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n, m, a, b;
	
	cin>>n>>m;
	
	while (m--)
	{
		cin>>a>>b;
		--a, --b;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	
	a = 0;
	prvi:
	bio[a] = true;
	sol.push_back(a);
	for (int b: edges[a]) if (!bio[b])
	{
		a = b;
		goto prvi;
	}
	
	a = 0;
	drugi:
	bio[a] = true;
	for (int b: edges[a]) if (!bio[b])
	{
		a = b;
		sol.push_front(b);
		goto drugi;
	}
	
	cout<<sol.size()<<'\n';
	for (int a: sol)
		cout<<a + 1<<' ';
	cout<<'\n';
}

