import std.stdio, std.string, std.algorithm, std.range, std.conv;

void main() {
  long N, M;
  readf(" %d %d ", &N, &M);
  
  long[][] edges;
  edges.length = N;
  foreach (i; 0..M) {
    long x, y;
    readf(" %d %d ", &x, &y);
    --x;
    --y;
    edges[x] ~= y;
  }
  
  auto dp = new long[N];
  dp[] = -1;
  long rec(long target) {
    if (dp[target] >= 0) return dp[target];
    
    dp[target] = 0;
    foreach (n; edges[target]) {
      dp[target] = dp[target].max(rec(n) + 1);
    }
    return dp[target];
  }
  
  long ans;
  foreach (i; 0..N) {
    ans = ans.max(rec(i));
  }
  ans.writeln;
}