#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <assert.h>
#include <map>
#include <set>

using namespace std;

int n, m, ti, mcol, color_ans, count_cycle, crendel;
vector<vector<vector<int> > > gg;
vector< vector<int> > g, id;
vector<int> enter, ret, color;
vector<int> used;
vector<int> answer, tmp;

void dfs(int v, int p = -1)
{
	used[v] = true;
	enter[v] = ret[v] = ti++;
	for (size_t i = 0; i < g[v].size(); i++)
	{
		int t = g[v][i];
		if (t == p) continue;
		if (used[t])
			ret[v] = min(ret[v], enter[t]);
		else
		{
			dfs(t, v);
			ret[v] = min(ret[v], ret[t]);
		}
	}
}

void paint(int v, int c, int p)
{
	used[v] = true;
	for (size_t i = 0; i < g[v].size(); i++)
	{
		int u = g[v][i];
		if (u == p) continue;
		if (!used[u])
		{
			if (ret[u] >= enter[v])
			{
				mcol++;
				color[id[v][i]] = mcol;
				paint(u, mcol, v);
			}
			else
			{
				color[id[v][i]] = c;
				paint(u, c, v);
			}
		}
		else
			if (enter[u] <= enter[v])
				color[id[v][i]] = c;
	}
};

bool path(int v, int col, int f)
{
	if (v == f) return true;
	if (used[v] == 0) used[v] = col;
	for (size_t i = 0; i < g[v].size(); i++)
	{
		if (used[g[v][i]] == 0) if (path(g[v][i], col, f)) return true;
		if (g[v][i] == f) return true;
	}
	return false;
}

void print(int v, int col1, int col2)
{
	tmp.push_back(v);
	used[v] = -1;
	for (size_t i = 0; i <g[v].size(); i++)
		if (used[g[v][i]] == 4 || used[g[v][i]] == col1 || used[g[v][i]] == col2)
			print(g[v][i], col1, col2);
}

bool find(int q)
{
	g = gg[q];
	int n = g.size();
	used.assign(n, false);
	size_t i = 0;
	while (i < g.size() && g[i].size() < 3) i++;
	size_t j = i + 1;
	while (j < g.size() && g[j].size() < 3) j++;
	if (j < g.size())
	{
		used[i] = used[j] = 4;
		path(g[i][0], 1, j), path(g[i][1], 2, j), path(g[i][2], 3, j);
		int c1 = 0, c2 = 0, c3 = 0;
		for (int ii = 0; ii < n; ii++)
			switch (used[ii])
		{
			case 1: c1++; break;
			case 2: c2++; break;
			case 3: c3++; break;
			default:
				break;
		}
		tmp.push_back(i);
		used[i] = -1;
		int len =  max(c1 + c2, max(c2 + c3, c1 + c3));
		if (len == c1 + c2) print(g[i][0], 1, 2);
		else 
			if (len == c2 + c3) print(g[i][1], 2, 3);
			else print(g[i][2], 1, 3);
		answer = tmp;
		color_ans = q;
		tmp.clear();
		count_cycle += 3;
		crendel++;
		return true;
	}
	for (int i = 0; i < n; i++)
		used[i] = (g[i].size() == 2) ? 4 : 0;
	i = 0;
	while (i < g.size() && g[i].size() != 2) i++;
	if (i < g.size())
	{
		print(i, 5, 6);
		count_cycle++;
	}
	if (answer.size() < tmp.size()) answer = tmp, color_ans = q;
	tmp.clear();
	return false;
}


void solve()
{
	cin >> n >> m;
	assert(1 <= n && n <= 2e5);
	assert(1 <= m && m <= 5e5);
	set<pair<int, int> > edges;
	g.resize(n, vector<int>()), id.resize(n, vector<int>()), used.resize(n, false), enter.resize(n, 0), ret.resize(n, 0);
	int x, y;
	for (int i = 0; i < m; i++)
	{
		cin >> x >> y;
		assert(x != y);
		pair<int, int> edge;
		if (x < y) edge = make_pair(x, y);
		else edge = make_pair(y, x);
		assert(edges.count(edge) == 0);
		edges.insert(edge);
		g[x - 1].push_back(y - 1); id[x - 1].push_back(i);
		g[y - 1].push_back(x - 1); id[y - 1].push_back(i);
	}
	ti = 0;
	for (int i = 0; i < n; i++)
		if (!used[i])
			dfs(i);
	color.clear();
	color.resize(m, 0);
	used.assign(n, false);
	mcol = 0;
	for (int i = 0; i < n; i++)
		if (!used[i])
			paint(i, -1, -1);
	
	vector<map<int, int> > cc(mcol), qq(mcol);
	for (int i = 0; i < n; i++)
		for (size_t j = 0; j < g[i].size(); j++)
		{	int cu = color[id[i][j]] - 1;
			int k = cc[cu].size();
			if (cc[cu].count(i) == 0) cc[cu][i] = k++, qq[cu][k - 1] = i;
			if (cc[cu].count(g[i][j]) == 0) cc[cu][g[i][j]] = k++, qq[cu][k - 1] = g[i][j];
        }

    gg.resize(mcol);

    for (int i = 0; i < mcol; i++)
    	gg[i].resize(cc[i].size());

    for (int i = 0; i < n; i++)
		for (size_t j = 0; j < g[i].size(); j++)
		{
			int cu = color[id[i][j]] - 1;
			gg[cu][cc[cu][i]].push_back(cc[cu][g[i][j]]);
	    }

	color.clear(), id.clear(), g.clear(), ret.clear(), enter.clear(), cc.clear();
	for (size_t i = 0; i < (size_t)mcol; i++)
		if (find(i)) break;

	cout << answer.size() << endl;
	for (size_t i = 0; i < answer.size(); i++)
		cout << qq[color_ans][answer[i]] + 1 << (i + 1 == answer.size() ? "\n" : " ");
}

int main()
{
	freopen("doggy.in", "r", stdin);
	freopen("doggy.out", "w", stdout);
	solve();
	cerr << count_cycle << " " << crendel << "\n";
	assert(count_cycle < 4);
}
