#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 1;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
vector<vector<int> > c;
int tim[N];
bool was[N];
int t;
void dfs(int v, int T) {
  if (was[v]) {
    t = gcd(t, abs(T - tim[v]));
    return;
  }
  was[v] = true;
  tim[v] = T;
  for (int i = 0; i < (int)(c[v]).size(); i++) {
    dfs(c[v][i], T + 1);
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  c.resize(n);
  for (int i = 0; i < n; i++) c[i].resize(0);
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--;
    y--;
    c[x].push_back(y);
  }
  t = 0;
  memset(was, false, sizeof was);
  memset(tim, 0, sizeof tim);
  dfs(0, 0);
  printf("%d\n", t);
  int all = 0;
  for (int i = 0; i < n; i++)
    if (tim[i] % t == 0 && was[i]) all++;
  printf("%d\n", all);
  for (int i = 0; i < n; i++)
    if (tim[i] % t == 0 && was[i]) printf("%d ", i + 1);
  return 0;
}
