#include <bits/stdc++.h>
using namespace std;
int n, m, label[100005], res;
int gcd(int a, int b);
vector<int> Ed[100005];
void Dfs(int x, int ord) {
  if (!label[x])
    label[x] = ord;
  else {
    res = !res ? (abs(ord - label[x])) : gcd(res, abs(ord - label[x]));
    return;
  }
  for (auto& v : Ed[x]) Dfs(v, ord + 1);
}
int main() {
  cin >> n >> m;
  for (int i = 0, u, v; i < m; i++) cin >> u >> v, Ed[u].push_back(v);
  Dfs(1, 1);
  int k = 0;
  for (int i = 1; i <= n; i++)
    if (label[i] && (label[i] - 1) % res == 0) k++;
  cout << res << endl;
  cout << k << endl;
  for (int i = 1; i <= n; i++)
    if (label[i] && (label[i] - 1) % res == 0) cout << i << ' ';
  return 0;
}
int gcd(int a, int b) {
  int t;
  while (a && b) t = a % b, a = b, b = t;
  return a | b;
}
