#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> g[100000];
vector<int> ans, nans, pos;
int dist[100000];
void dfs(int v) {
  for (int to : g[v])
    if (dist[to] == -1) {
      dist[to] = dist[v] + 1;
      dfs(to);
    }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (int)(m); ++i) {
    int from, to;
    scanf("%d%d", &from, &to), --from, --to;
    g[from].push_back(to);
  }
  for (int i = n; i >= 1; --i) ans.push_back(i);
  for (int i = 0; i < (int)(n); ++i) dist[i] = -1;
  dist[0] = 0;
  dfs(0);
  for (int v = 0; v < (int)(n); ++v)
    if (dist[v] != -1)
      for (int to : g[v])
        if (dist[to] != dist[v] + 1) {
          int a = dist[v];
          int b = dist[to];
          for (int x : ans)
            if ((a + 1) % x == b % x) {
              nans.push_back(x);
            }
          ans = nans;
          nans.clear();
        }
  int best = ans[0];
  for (int v = 0; v < (int)(n); ++v)
    if (dist[v] != -1) dist[v] %= best;
  for (int v = 0; v < (int)(n); ++v)
    if (dist[v] == 0) {
      pos.push_back(v + 1);
    }
  printf("%d\n%d\n", best, (int)pos.size());
  for (int x : pos) printf("%d ", x);
  printf("\n");
  return 0;
}
