#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <queue>

#define rep(i, l, r) for(int i = l; i <= r; i++)
#define down(i, l, r) for(int i = l; i >= r; i--)
#define MS 123456
#define MAX 1037471823
#define Q 103

using namespace std;

struct node
{
	int x, y;
	bool operator < (const node &k) const { return x < k.x; }
} c[MS];
int n, d[MS], l[MS], h[MS], ys, k[MS], m, s[MS], a, v[MS], vv;
bool b[MS];

void DFS(int x)
{
	v[++vv] = x; d[x] = vv; l[x] = vv;
	rep(i, k[x], k[x+1]-1)
	{
		 if (d[c[i].y] == 0) DFS(c[i].y); 
		 l[x] = min(l[x], l[c[i].y]);
	}
	if (d[x] == l[x])
	{
		ys++;
		rep(i, d[x], vv) h[v[i]] = ys;
		s[ys] = vv-d[x]+1;
		vv = d[x]-1;
	}
}

int main()
{
	scanf("%d%d", &n, &m);
	rep(i, 1, m) scanf("%d%d", &c[i].x, &c[i].y);
	sort(c+1, c+1+m); c[m+1].x = MAX;
	k[1] = 1; rep(i, 2, n+1) { k[i] = k[i-1]; while (c[k[i]].x < i) k[i]++; }
	rep(i, 1, n) l[i] = MAX;
	rep(i, 1, n) if (h[i] == 0) DFS(i);
	rep(i, 1, ys) b[i] = true;
	rep(i, 1, m) if (h[c[i].x] != h[c[i].y]) b[h[c[i].x]] = false;
	a = 0; rep(i, 1, ys) if (b[i]) a++;
	if (a != 1) printf("0\n"); else
		rep(i, 1, ys) if (b[i]) printf("%d\n", s[i]);
	return 0;
}
