There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G **does not contain directed cycles**.  Find the length of the longest directed path in G. Here, the length of a directed path is the number of edges in it.
import sys

sys.setrecursionlimit(10**5+10)

N, M = [int(_) for _ in input().split()]


lst_edge = [[] for _ in range(N)]

for _ in range(M):
  x, y = map(int, input().split()) 
  
  lst_edge[x-1].append(y-1)
  print(lst_edge)
        


dp = [-1] * N


def rec(v):
  
  if dp[v] != -1:
    return dp[v]
  ans = 0
  lst_nv = lst_edge[v]
  for nv in lst_nv:
    ans = max(ans, rec(nv) + 1)
  dp[v] = ans
  return dp[v]
    

ans = 0
for v in range(N):
  ans = max(ans, rec(v))
    
print(ans)
    
import sys

sys.setrecursionlimit(10**5+10)

N, M = [int(_) for _ in input().split()]


lst_edge = [[] for _ in range(N)]

for _ in range(M):
  
  x, y = [int(_)-1 for _ in input().split()] 
  lst_edge[x].append(y)
        


dp = [-1] * N


def rec(v):
  
  if dp[v] != -1:
    return dp[v]
  ans = 0
  lst_nv = lst_edge[v] 
  for nv in lst_nv:
    ans = max(ans, rec(nv) + 1) 
  dp[v] = ans 
  return dp[v]
    

ans = 0
for v in range(N):
  ans = max(ans, rec(v))
    
print(ans)
    