#include <bits/stdc++.h>
using namespace std;
int n,m,dp[100009];
vector < int > v[100009];
int dfs(int node){
	int &ret = dp[node];
	if(ret != -1) return ret;
	ret = 0;
	for(int i=0;i<v[node].size();i++){
		int u = v[node][i];
		ret = max(ret,dfs(u)+1);
	}
	return ret;
}
int main(){
	memset(dp,-1,sizeof(dp));
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		v[a].push_back(b);
	}
	int mx = 0;
	for(int i=0;i<n;i++){
		mx = max(mx,dfs(i));
	}
	cout<<mx<<endl;
}
