func_code_string: #include <bits/stdc++.h>   using namespace std;   vector<vector<pair<int, int> > > adj;   vector<int> in;   vector<int> out;   vector<pair<int, int> > visit;   pair<int, int> cal(int son) {     if (visit[son].first > 0) return visit[son];     if (visit[son].first == -2) return {-1, -1};     visit[son] = {-2, 0};     pair<int, int> temp, ans = {0, 0};     for (int i = 0; i < adj[son].size(); ++i) {       temp = cal(adj[son][i].first);       if (temp.first == -1) return temp;       if (temp.first > ans.first) {         ans.first = temp.first;         ans.second = max(temp.second, adj[son][i].second);       }     }     ++ans.first;     visit[son] = ans;     return visit[son];   }   int main() {     int n, m;     cin >> n >> m;     adj.resize(n + 1);     out.resize(n + 1);     in.resize(n + 1);     visit.resize(n + 1, {-1, 0});     int num1, num2;     for (int i = 0; i < m; ++i) {       cin >> num1 >> num2;       out[num1]++;       in[num2]++;       adj[num1].push_back({num2, i});     }     int node = 0, cnt = 0;     for (int i = 1; i <= n; ++i) {       if (in[i] == 0) {         node = i;         ++cnt;       }     }     if (cnt != 1) {       cout << -1 << endl;       return 0;     }     pair<int, int> temp = cal(node);     if (temp.second == -1 || temp.first != n)       cout << -1 << endl;     else       cout << temp.second + 1 << endl;     return 0;   }   