#include<vector>
#include<cstdio>
#include<algorithm>
using namespace std;

vector<int> adj[100005];
int vis[100005], dp[100005];

void dfs( int u ) {
	vis[u] = 1;
	for( int v : adj[u] )
	{
		if( vis[v] == 0 )
			dfs(v);
		dp[u] = max(dp[u], 1+dp[v]);
	}
}

int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for( int i=0, u, v; i<m; ++i )
		scanf("%d%d", &u, &v), adj[u].push_back(v);
	int ans = -1;
	for( int i=1; i<=n; ++i ) {
		if( vis[i] == 0 )
			dfs(i);
		ans = max(ans, dp[i]);
	}
	printf("%d\n", ans);
}	
