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

const int DIM = 1e5 + 5;

deque<int> ans; bitset<DIM> oki;
vector<int> edg[DIM];

bool good(int x, bool pos)
{
    for (int y : edg[x]) {
        if (oki[y])
            continue;
        
        oki[y] = true;
        if (pos) ans.push_back(y);
        else     ans.push_front(y);
        
        return false;
    }
    
    return true;
}

int main(void)
{
    int n, m; cin >> n >> m;
    for (int i = 1; i <= m; ++i) {
        int x, y; cin >> x >> y;
        
        edg[x].push_back(y);
        edg[y].push_back(x);
    }
    
    ans.push_back(1); oki[1] = true;
    while (true) {
        if (good(ans.front(), false) and good(ans.back(), true))
            break;
    }
    
    cout << ans.size() << endl;
    for (int x : ans)
        cout << x << " ";
    
    return 0;
}