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: #include <bits/stdc++.h>
  using namespace std;
  typedef long long ll;
  #define rep(i, n) for (int i = 0; i < n; ++i)
  #pragma region Debug
  template <typename T>
  void view(const std::vector<T> &v)
  {
      for (const auto &e : v)
      {
          std::cout << e << " ";
      }
      std::cout << std::endl;
  }
  template <typename T>
  void view(const std::vector<std::vector<T>> &vv)
  {
      for (const auto &v : vv)
      {
          view(v);
      }
  }
  #pragma endregion
  template <typename T>
  inline bool chmax(T &a, T b)
  {
      if (a < b)
      {
          a = b;
          return true;
      }
      return false;
  }
  
  map<int, vector<int>> dag;
  vector<int> max_depth;
  int ans = 0;
  void dfs(int v, int d = 0)
  {
      chmax(max_depth[v], d);
      chmax(ans, max_depth[v]);
      for (auto &child : dag[v])
      {
          dfs(child, d + 1);
      }
  }
  
  int main()
  {
      int n, m;
      cin >> n >> m;
      vector<bool> start(n, true);
      max_depth = vector<int>(n, 0);
      rep(i, m)
      {
          int x, y;
          cin >> x >> y;
          x--;
          y--;
          dag[x].push_back(y);
          start[y] = false;
      }
  
      rep(i, n)
      {
          if (!start[i])
              continue;
  
          dfs(i);
      }
  
      cout << ans << endl;
  
      return 0;
  }
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)"}]