#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
bool in[N];
vector<vector<int> > g;
int main() {
//freopen("readin.txt", "r", stdin);
deque<int> q;
int n, m;
scanf("%d%d", &n, &m);
g.resize(n + 1);
for (int i = 0, a, b; i < m; i++) {
scanf("%d%d", &a, &b);
g[a].push_back(b);
swap(a, b);
g[a].push_back(b);
}
in[1] = true;
q.push_front(1);
while (1) {
int a = q.front();
int b = q.back();
bool c1 = 0, c2 = 0;
for (int i = 0; i < g[a].size(); i++) {
int v = g[a][i];
if (!in[v]) {
c1 = true;
in[v] = true;
q.push_front(v);
break;
}
}
for (int i = 0; i < g[b].size(); i++) {
int v = g[b][i];
if (!in[v]) {
c2 = true;
in[v] = true;
q.push_back(v);
break;
}
}
if (!c1 && !c2) break;
}
cout << q.size() << endl;
while (q.size()) {
printf("%d ", q.front());
q.pop_front();
}
}