#include <bits/stdc++.h>
using namespace std;

vector<int> graph[100005];
bool visit[100005];

vector<int> path;
vector<int> path2;

void dfs(int t)
{
    visit[t] = true;
    path.push_back(t);
    for (int nxt : graph[t])
    {
        if (visit[nxt] == false)
        {
            dfs(nxt);
            return;
        }
    }
}

int main()
{
    cin.sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    dfs(1);
    swap(path, path2);
    dfs(1);

    printf("%zd\n", path.size() + path2.size() - 1);
    for (int i = (int)path2.size() - 1; i >= 1; i--)
    {
        printf("%d ", path2[i]);
    }
    for (int t : path) printf("%d ", t);
    printf("\n");
}
