func_code_string: #include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > v;   int n, m, vis[100005], in[100005], d[100005];   vector<int> e[100005];   int dfs(int i) {     vis[i] = 1;     int ans = 0;     for (auto first : e[i]) {       if (vis[first]) {         ans = max(ans, d[first]);         continue;       }       ans = max(ans, dfs(first));     }     d[i] = ans + 1;     return ans + 1;   }   bool check(int first) {     int j;     for (int i = 0; i < n; i++) {       e[i].clear();       vis[i] = 0;       in[i] = 0;       d[i] = 0;     }     for (int i = 0; i < first; i++) {       e[v[i].first].push_back(v[i].second);       in[v[i].second]++;     }     int f;     for (int i = 0; i < n; i++)       if (in[i] == 0) {         j = i;         f = dfs(i);         break;       }     return f == n;   }   void solve() {     int first, second;     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> first >> second;       first--;       second--;       v.push_back({first, second});     }     int l = 1, r = m, mid;     while (l < r) {       mid = l + (r - l) / 2;       if (check(mid))         r = mid;       else         l = mid + 1;     }     if (check(l))       cout << l <<   n ;     else       cout << -1;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     }     return 0;   }   