#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

class UnionFind {
    struct UFNode {
        int par;
        int rank;
    };
    vector<UFNode> nodes;
public:
    UnionFind(int n): nodes(n) {
        for (int i = 0; i < n; i++) {
            nodes[i].par = i;
            nodes[i].rank = 0;
        }
    };
    int root(int x) {
        return nodes[x].par == x ? x : nodes[x].par = root(nodes[x].par);
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (nodes[x].rank < nodes[y].rank) {
            nodes[x].par = y;
        } else {
            nodes[y].par = x;
            if (nodes[x].rank == nodes[y].rank) nodes[x].rank++;
        }
    }
    //~UnionFind() {cout << nodes.size() << endl;}
};

void solve() {
    int n,m;
    cin >> n >> m;
    VVI es(n);
    int a,b;
    int l, r;
    REP(i,0,m) {
        cin >> a >> b;
        --a; --b;
        es[a].push_back(b);
        es[b].push_back(a);
        if (i == 0) {
            l = a;
            r = b;
        }
    }
    vector<bool> used(n);
    VI par(n,-1);
    used[l] = used[r] = true;
    while (true) {
        //dump(l);
        bool b = true;
        for (int dst: es[l]) {
            if (used[dst]) continue;
            b = false;
            par[dst] = l;
            used[dst] = true;
            l = dst;
            break;
        }
        if (b) break;
    }
    while (true) {
        //dump(r);
        bool b = true;
        for (int dst: es[r]) {
            if (used[dst]) continue;
            b = false;
            par[dst] = r;
            used[dst] = true;
            r = dst;
            break;
        }
        if (b) break;
    }
    VI ls, rs;
    while (l != -1) {
        ls.push_back(l);
        l = par[l];
    }
    while (r != -1) {
        rs.push_back(r);
        r = par[r];
    }
    reverse(all(rs));

    cout << ls.size() + rs.size() << endl;
    for (int v: ls) cout << v + 1 << " ";
    for (int v: rs) cout << v + 1 << " ";
    cout << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 7160