#include <bits/stdc++.h>
using namespace std;
int n, m, a, b, cnt[5005], maxCnt;
bool hi[5005], vis[5005];
vector<int> v[5005];
void topSort(int x) {
queue<int> q;
q.push(x);
while (!q.empty()) {
int u = q.front();
q.pop();
for (auto i : v[u]) {
if (!vis[i]) {
q.push(i);
vis[i] = true;
}
cnt[i] = (cnt[i] + cnt[u]) % 80112002;
}
}
}
int main() {
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cin >> a >> b;
v[a].push_back(b);
hi[b] = true;
}
for (int x = 1; x <= n; x++)
if (!hi[x]) {
memset(vis, false, sizeof vis);
cnt[x] = 1;
topSort(x);
}
for (int i = 1; i <= n; i++)
maxCnt = max(maxCnt, cnt[i]);
cout << maxCnt;
return 0;
}