#include<cstdio>
#include<cstring>
const int N=100005;
const int M=200005;
using namespace std;
#include<vector>

struct EDGE
{
    int v,next;
}edge[M*2],ed2[M*2];
int first[N],low[N],dfn[N],belong[N],degree[N],sta[M],instack[M];
int aaa[N],nok[N],first2[N],bbb[N],countt[N];
int g,cnt,top,scc,g2;
int n,m;
int dd[N],fa[N];
vector<int > ans1,ans2;
int min(int a,int b)
{
    return a<b?a:b;
}
void AddEdge(int u,int v)
{
    edge[g].v=v;
    edge[g].next=first[u];
    first[u]=g++;
}
void AddEdge2(int u,int v)
{
    //printf("!!!!!!!!!%d %d\n",u,v);
    ed2[g2].v=v;
    ed2[g2].next=first2[u];
    first2[u]=g2++;
}
void Tarjan(int u,int fa)
{
    int i,v;
    low[u]=dfn[u]=++cnt;
    sta[++top]=u;
    instack[u]=1;
    for(i=first[u];i!=-1;i=edge[i].next)
    {
        v=edge[i].v;
        if(i==(fa^1))
            continue;
        if(!dfn[v])
        {
            Tarjan(v,i);
            low[u]=min(low[u],low[v]);
        }
        else if(instack[v])
            low[u]=min(low[u],dfn[v]);
    }
    if(dfn[u]==low[u])
    {
        scc++;
        while(1)
        {
            v=sta[top--];
            instack[v]=0;
            belong[v]=scc;
            countt[scc]++;
            if(v==u)
                break;
        }
    }
}
void dfs1(int u)
{
    bbb[u]=1;ans1.push_back(u);
    int i,v;
    for(i=first2[u];i!=-1;i=ed2[i].next)
    {
        v=ed2[i].v;
        if (!bbb[v]) {

            dfs1(v);
            break;
        }
    }
}
void dfs2(int u)
{
    bbb[u]=1;ans2.push_back(u);
    int i,v;
    for(i=first2[u];i!=-1;i=ed2[i].next)
    {
        v=ed2[i].v;
        if (!bbb[v]) {
            dfs2(v);
            break;
        }
    }
}
void dfsmy(int u)
{
    bbb[u]=1;
    int i,v;
    for(i=first[u];i!=-1;i=edge[i].next)
    {
        v=edge[i].v;
        if (!bbb[v]) {
            fa[v]=u;
            dfsmy(v);
        }
    }
}
void doit()
{
    int u,v,i,j;
    g=cnt=top=scc=0;g2=0;
    memset(first,-1,sizeof(first));
    memset(first2,-1,sizeof(first2));
    memset(low,0,sizeof(low));
    memset(dfn,0,sizeof(dfn));
    memset(instack,0,sizeof(instack));
    memset(degree,0,sizeof(degree));
    memset(countt,0,sizeof(countt));
    memset(dd,0,sizeof(dd));
    for(i=0;i<m;i++)
    {
        scanf("%d%d",&u,&v);
        {
            AddEdge(u,v);
            AddEdge(v,u);
            dd[u]++;
            dd[v]++;
        }
    }
    int sp=-1,tp=-1;
    for(i=1;i<=n;i++)if (dd[i]==1) {sp=i;break;}
    for(i=1;i<=n;i++)if (dd[i]==1&&i!=sp) {tp=i;break;}
    if (sp!=-1&&tp!=-1)
    {
        memset(bbb,0,sizeof(bbb));
        dfsmy(sp);
        int x=tp,y=0;
        while (x!=sp)
        {
            y++;
            x=fa[x];
        }
        printf("%d\n",y+1);
        x=tp;
        while (x!=sp)
        {
            printf("%d ",x);
            x=fa[x];
        }
        printf("%d ",sp);
        return;
    }


        if(!dfn[i])
            Tarjan(1,-1);
    for(i=1;i<=n;i++)
    {
        for(j=first[i];j!=-1;j=edge[j].next)
        {
            v=edge[j].v;
            if(belong[i]!=belong[v])
            {
                degree[belong[i]]++;
                nok[i]=1;
                nok[v]=1;
            }
        }
    }
    int id,ma=0;
    for(int i=1;i<=scc;i++)
        if (countt[i]>ma)
        {
            ma=countt[i];
            id=i;
        }
    memset(aaa,0,sizeof(aaa));
    for (int i=1;i<=n;i++)
        if (belong[i]==id) {
            aaa[i] = 1;

        }






    for(i=1;i<=n;i++)if (aaa[i])
    {
        for(j=first[i];j!=-1;j=edge[j].next)
        {
            v=edge[j].v;
            if (!aaa[v])continue;
            AddEdge2(i,v);
        }
    }

    int root;
    for (int i=1;i<=n;i++)if (aaa[i]&&!nok[i])
        {
            root=i;
            break;
        }
    //printf("@@@@@@@@@%d\n",root);

    memset(bbb,0,sizeof(bbb));
    dfs1(root);
    bbb[root]=0;
    dfs2(root);
    printf("%d\n",ans1.size()+ans2.size()-1);
    int sz=ans2.size();
    for (int i=sz-1;i>=0;i--)
        printf("%d ",ans2[i]);
    sz=ans1.size();
    for (int i=1;i<sz;i++)
        printf("%d ",ans1[i]);
}
int main()
{

    scanf("%d%d",&n,&m);
    doit();
}

Measured memory_bytes: 15872