// testneveles.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <queue>
#define ll long long
using namespace std;
ll n, m;
struct adat
{
bool lat1 = false,lat=false;
ll latk = 0,csop;
vector<ll>sz,sz2;
};
deque<ll>ans, ans2;
vector<adat>x;
bool ok1 = false;
void melyk(int csp)
{
if (ok1 == true)return;
x[csp].latk = 1;
for (auto& e:x[csp].sz)
{
if (!x[e].latk)melyk(e);
else if (x[e].latk != 2)
{
ok1 = true;
break;
}
}
x[csp].latk = 2;
}
void mely(int csp,int csop)
{
x[csp].lat = true;
x[csp].csop = csop;
for (auto& e : x[csp].sz2)
if (!x[e].lat)mely(e,csop);
//ans.push_front(csp);
}
void mely2(int csp)
{
x[csp].lat1 = true;
for (auto& e : x[csp].sz)
if (!x[e].lat1)mely2(e);
ans.push_front(csp);
}
void mely3(int csp)
{
x[csp].lat1 = true;
for (auto& e : x[csp].sz)
if (!x[e].lat1)mely2(e);
ans2.push_front(csp);
}
int main()
{
cin >> n >> m;
x.resize(n + 1);
for (int i = 1; i <= m; ++i)
{
ll a, b;
cin >> a >> b;
x[a].sz.push_back(b);
x[a].sz2.push_back(b);
x[b].sz2.push_back(a);
}
bool ok = false, ok2 = false;
for (int i = 1; i <= n; ++i)
{
if (!x[i].latk)melyk(i);
}
if (ok1)
{
cout << "0";
return 0;
}
int csp=0;
for (int i = 1; i <= n; ++i)
{
if (!x[i].lat)
{
csp++;
mely(i,csp);
}
cout << i << " " << csp << "\n";
}
for (int i = 1; i <= n; ++i)
{
if (!x[i].lat1)
{
if (x[i].csop != 1)
mely3(i);
else mely2(i);
}
}
if (csp>1)
{
cout << "2" << "\n";
}
else cout << "1"<<"\n";
for (auto& e : ans)cout << e << " ";
if (csp>1)
{
for (auto& e : ans2)cout << e << " ";
cout << "\n";
for (auto& e : ans2)cout << e << " ";
for (auto& e : ans)cout << e << " ";
}
return 0;
}
/* 5 9
3 1
3 5
3 4
4 2
3 2
1 4
1 2
1 5
5 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