output_description: Print the length of the longest directed path in G.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N M
      x_1 y_1
      x_2 y_2
      :
      x_M y_M
attempt: from collections import Counter
  from collections import defaultdict
  import math
  import random
  import heapq as hq
  from math import sqrt
  import sys
  from functools import reduce
  
  
  def input():
      return sys.stdin.readline().strip()
  
  
  def iinput():
      return int(input())
  
  
  def tinput():
      return input().split()
  
  
  def rinput():
      return map(int, tinput())
  
  
  def rlinput():
      return list(rinput())
  
  
  mod = int(1e9) + 7
  
  
  def factors(n):
      return set(
          reduce(
              list.__add__, ([i, n // i] for i in range(1, int(n**0.5) + 1) if n % i == 0)
          )
      )
  
  
  # ----------------------------------------------------
  
  
  def dfs(i):
      visited[i] = True
      for node in g[i]:
          if not visited[node]:
              dfs(node)
          dp[i] = max(dp[i], 1 + dp[node])
  
  
  if __name__ == "__main__":
      n, m = rinput()
      g = defaultdict(list)
      for i in range(m):
          x, y = rinput()
          g[x].append(y)
      dp = [0] * (n + 1)
      visited = [False] * (n + 1)
      for i in range(1, n + 1):
          if not visited[i]:
              dfs(i)
              # print('-=============================')
      # print(dp)
      print(max(dp))
  
  
  # 5 3
  # 2 3
  # 2 4
  # 5 2
  # 5 1
  # 1 4
  # 4 3
  # 1 3
  
problem_description: Statement
  
  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.
samples: [{"input": "4 5\n    1 2\n    1 3\n    3 2\n    2 4\n    3 4", "output": "3\n    \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_0_muffet.png)\n\n* * *"}, {"input": "6 3\n    2 3\n    4 5\n    5 6", "output": "2\n    \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_1_muffet.png)\n\n* * *"}, {"input": "5 8\n    5 3\n    2 3\n    2 4\n    5 2\n    5 1\n    1 4\n    4 3\n    1 3", "output": "3\n    \n\nThe red directed path in the following figure is one of the longest:\n\n![](https://img.atcoder.jp/dp/longest_2_muffet.png)"}]