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

using namespace std;

vector<bool> used;
vector<vector<int> > a;
vector<int> path;

int countr = 0;

void dfs (int v) {
	used[v] = true;
	countr += 1;
	path.push_back(v);
	for(unsigned i = 0; i < a[v].size(); i++)
		if(!used[a[v][i]]) 
			dfs(a[v][i]);
}

int main () {

	int n, m;
	cin >> n >> m;

	a.resize(n);
	used.resize(n);

	for(int i = 0; i < m; i++) {
		int v, u;
		cin >> v >> u;
		a[v-1].push_back(u-1);
		a[u-1].push_back(v-1);
	}
	dfs(0);

	cout << countr << endl;
	for(unsigned i = 0; i < path.size(); i++)
		cout << (path[i] + 1) << ' ';
	return 0;
}