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+1)

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

for _ in range(M):
  x,y = map(int,input().split())
  nodes[x-1].append(y-1)
  
dp = [-1]*N

def judge(index):
  if dp[index] != -1:
    return dp[index]
  else:
    edges = 0
    for i in nodes[index]:
      edges = max(edges, 1+judge(i))
    dp[index] = edges
    print(index,dp)
    return edges

answer = 0
for i in range(N):
  answer = max(answer, judge(i))
print(answer)
import sys
sys.setrecursionlimit(10**5+1)

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

for _ in range(M):
  x,y = map(int,input().split())
  nodes[x-1].append(y-1)
  
dp = [-1]*N

def judge(index):
  if dp[index] != -1:
    return dp[index]
  else:
    edges = 0
    for i in nodes[index]:
      edges = max(edges, 1+judge(i))
    dp[index] = edges
    return edges

answer = 0
for i in range(N):
  answer = max(answer, judge(i))
print(answer)