// zsakfalvak.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <deque>
#include <vector>
#include <algorithm>
using namespace std;
struct adat
{
int lep, lat;
vector<int>sz;
};
deque<adat>x;
int akt;
deque<int>v,y,megold,megoldb;
int n, a, b, i, kezd,m;
int main()
{
cin >> n>>m;
x.resize(n + 1);
megoldb.resize(n + 1);
for (i = 1; i <= m; ++i)
{
cin >> a >> b;
x[a].sz.push_back(b);
x[b].sz.push_back(a);
}
for (i = 1; i <= n; ++i)
if (x[i].sz.size() == 1)
{
y.push_back(i);
}
i = 0;
while (!y.empty())
{
i++;
v.push_back(y.front());
//y.pop_front();
x[v.front()].lat = i;
while (!v.empty())
{
akt = v.front();
v.pop_front();
for (auto& e : x[akt].sz)
{
if (x[e].sz.size() <= 2 &&x[e].lat<x[akt].lat)
{
x[e].lat = x[akt].lat;
v.push_back(e);
if (!megoldb[e]) megold.push_back(e);
megoldb[e] = 1;
}
else if (x[akt].sz.size() <= 2 && x[e].lat < x[akt].lat)
{
if (!megoldb[e]) megold.push_back(e);
megoldb[e]=1;
x[e].lat = x[akt].lat;
}
}
}
y.pop_front();
}
if (megold.size())
{
cout << megold.size() << "\n";
sort(megold.begin(), megold.end());
for (i = 0; i < megold.size(); ++i) cout << megold[i] << " ";
}
else cout << 0 << "\n";
return 0;
}
/*
8 9
1 2
1 6
2 7
1 5
3 4
4 5
5 6
6 7
8 7
4 3
1 2
2 3
3 4
*/
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu
// Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file