#include <iostream> using namespace std; int n,m,i,j,a,b,head,tail,ans; int graph[100][100]; int degree[100]; int len[100]; int queue[100]; int main() { cin>>n>>m; for(i=0; i<n; i++) for(j=0; j<n; j++) graph[i][j]=0; for(i=0; i<n; i++) degree[i]=0; for(i=0; i<m; i++) { cin>>a>> b; graph[a][b]=1; (degree[b]++); } tail = 0; for (int i=0; i<n; i++) if(!degree[i]) { queue[tail]=i; tail++; } head= 0; while (tail<n) { for (i=0; i<n; i++) if (graph[queue[head]][i]== 1) { (degree[i]--); if (degree[i]==0) { queue[tail] = i; tail++; } } (++head); } ans = 0; for (i=0; i<n; i++) { a =queue[i]; len[a]=1; for (j=0; j<n; j++) if(graph[j][a]==1&& len[j]+1>len[a]) len[a]=len[j]+1; if((len[a]> ans)) ans = len[a]; } cout<<ans<<endl; return 0; }