#include <bits/stdc++.h>
using namespace std;
int n, m;
const int INF = 2147483647;
map<int, vector<int>> path;
int d[100005];
void dfs(int i, int deep) {
  if (d[i] != -1) {
    return;
  }
  d[i] = deep;
  map<int, vector<int>>::iterator iter = path.find(i);
  if (iter != path.end()) {
    vector<int> v = path[i];
    for (int j = 0; j < v.size(); j++) {
      dfs(v[j], deep + 1);
    }
  }
}
int mc(int x, int y) {
  int z = y;
  while (x % y != 0) {
    z = x % y;
    x = y;
    y = z;
  }
  return z;
}
int main() {
  scanf("%d%d", &n, &m);
  int x, y;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    map<int, vector<int>>::iterator iter = path.find(x);
    if (iter == path.end()) {
      vector<int> v;
      v.push_back(y);
      path[x] = v;
    } else {
      iter->second.push_back(y);
    }
  }
  memset(d, -1, sizeof d);
  dfs(1, 0);
  vector<int> dv, ans;
  for (map<int, vector<int>>::iterator iter = path.begin(); iter != path.end();
       iter++) {
    int start = iter->first;
    for (vector<int>::iterator itt = iter->second.begin();
         itt != iter->second.end(); itt++) {
      int end = *itt;
      if (d[start] != -1 && d[end] != -1) {
        int dis = abs(d[start] + 1 - d[end]);
        if (dis != 0) dv.push_back(dis);
      }
    }
  }
  int ss = dv.size();
  int t = 1;
  if (ss == 1) {
    t = dv[0];
  } else {
    t = mc(max(dv[0], dv[1]), min(dv[0], dv[1]));
    for (int i = 2; i < ss; i++) {
      t = mc(max(dv[i], t), min(dv[i], t));
    }
  }
  int k = 0;
  for (int i = 1; i <= n; i++) {
    if (d[i] != -1 && d[i] % t == 0) {
      k++;
      ans.push_back(i);
    }
  }
  printf("%d\n%d\n", t, k);
  for (vector<int>::iterator itt = ans.begin(); itt != ans.end(); itt++) {
    printf("%d ", *itt);
  }
  return 0;
}
