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: import sys
   
  sys.setrecursionlimit(150000)sys.setrecursionlimit(150000)
  
  def gdp(n, dp, G):
      if dp[n]!=-1:
          return dp[n]
   
      if G[n]==[]:
          dp[n]=0
          return 0
   
      for i in G[n]:
          ll=gdp(i, dp, G)
          if dp[n]<ll+1:
              dp[n]=ll+1
   
      return dp[n]
   
  def solve(N: int, M: int, x: "List[int]", y: "List[int]"):
      G=[[] for _ in range(N)]
      for i in range(M):
          G[x[i]-1].append(y[i]-1)
   
      dp=[-1]*N
   
      print(max(gdp(i, dp, G) for i in range(N)))
   
      return
   
   
  # Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
  def main():
      def iterate_tokens():
          for line in sys.stdin:
              for word in line.split():
                  yield word
      tokens = iterate_tokens()
      N = int(next(tokens))  # type: int
      M = int(next(tokens))  # type: int
      x = [int()] * (M)  # type: "List[int]"
      y = [int()] * (M)  # type: "List[int]"
      for i in range(M):
          x[i] = int(next(tokens))
          y[i] = int(next(tokens))
      solve(N, M, x, y)
   
  if __name__ == '__main__':
      main()
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)"}]