#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100111];
int res;
bool visited[100111];
int dp[100111];
int m, n;
int DFS(int u) {
if (dp[u]) return dp[u];
for (int i = 0; i < adj[u].size(); i += 1) {
int v = adj[u][i];
dp[u] = max(dp[u], DFS(v) + 1);
}
return dp[u];
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> m >> n;
for (int i = 1, u, v; i <= n; i += 1) {
cin >> u >> v;
adj[u].push_back(v);
}
for (int i = 1; i <= m; i += 1) {
res = max(res, DFS(i));
}
cout << res;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdmVjdG9yPGludD4gYWRqWzEwMDExMV07CmludCByZXM7CmJvb2wgdmlzaXRlZFsxMDAxMTFdOwppbnQgZHBbMTAwMTExXTsKaW50IG0sIG47CgppbnQgREZTKGludCB1KSB7CiAgICBpZiAoZHBbdV0pIHJldHVybiBkcFt1XTsKCiAgICBmb3IgKGludCBpID0gMDsgaSA8IGFkalt1XS5zaXplKCk7IGkgKz0gMSkgewogICAgICAgIGludCB2ID0gYWRqW3VdW2ldOwogICAgICAgIGRwW3VdID0gbWF4KGRwW3VdLCBERlModikgKyAxKTsKICAgIH0KCiAgICByZXR1cm4gZHBbdV07Cn0KCmludDMyX3QgbWFpbigpIHsKICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogICAgY2luLnRpZShOVUxMKTsKCiAgICBjaW4gPj4gbSA+PiBuOwogICAgZm9yIChpbnQgaSA9IDEsIHUsIHY7IGkgPD0gbjsgaSArPSAxKSB7CiAgICAgICAgY2luID4+IHUgPj4gdjsKICAgICAgICBhZGpbdV0ucHVzaF9iYWNrKHYpOwogICAgfQoKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG07IGkgKz0gMSkgewogICAgICAgIHJlcyA9IG1heChyZXMsIERGUyhpKSk7CiAgICB9CiAgICAKICAgIGNvdXQgPDwgcmVzOwogICAgcmV0dXJuIDA7Cn0=