func_code_string: #include <bits/stdc++.h>   using namespace std;   long long N = 1e5 + 10;   vector<vector<long long> > v1(N, vector<long long>(2));   vector<vector<long long> > v;   long long dfs(long long s, long long n, vector<long long>& level) {     long long val = 0;     for (auto u : v[s]) {       if (level[u] == 0) {         val = max(val, dfs(u, n, level));       } else if (level[u]) {         val = max(val, level[u]);       }     }     level[s] = val + 1;     return level[s];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, m;     cin >> n >> m;     for (long long i = 1; i <= m; i++) {       cin >> v1[i][0] >> v1[i][1];     }     long long low = 1, high = m, ans = -1;     while (low <= high) {       long long mid = (low + high) / 2;       v.clear();       v.resize(n + 1);       vector<long long> par(n + 1, -1), level(n + 1);       for (long long i = 1; i <= mid; i++) {         v[v1[i][0]].push_back(v1[i][1]);         par[v1[i][1]] = v1[i][0];       }       for (long long i = 1; i <= n; i++) {         if (par[i] == -1) {           if (dfs(i, n, level) == n) {             ans = mid;             high = mid - 1;           } else {             low = mid + 1;           }           break;         }       }     }     cout << ans;     return 0;   }   