func_code_string: #include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast )   #pragma GCC optimize( no-stack-protector )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native )   #pragma GCC optimize( fast-math )   const long long N = 1e6 + 5;   const long double EPS = 1e-12;   const long long INF = 2e18 + 5;   const long long MOD = 1e9 + 7;   const long double PI = 3.14159265358979323;   vector<set<long long> > g;   vector<pair<long long, long long> > a;   vector<long long> ans, u;   void dfs(long long v) {     u[v] = 1;     for (auto &i : g[v])       if (!u[i]) dfs(i);     ans.push_back(v);   }   void topsort(long long n) {     ans.clear();     for (long long i = 0; i < n; i++) {       if (!u[i]) dfs(i);     }     reverse(ans.begin(), ans.end());   }   bool bin(long long n, long long m) {     for (long long i = 0; i < n; i++) {       g[i].clear();       u[i] = 0;     }     for (long long i = 0; i < m; i++) {       g[a[i].first].insert(a[i].second);     }     topsort(n);     for (long long i = 0; i + 1 < ans.size(); i++) {       if (g[ans[i]].find(ans[i + 1]) == g[ans[i]].end()) return 0;     }     return 1;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long ttt = 1;     for (; ttt; --ttt) {       long long n, m;       cin >> n >> m;       a.resize(m);       g.resize(n);       u.resize(n);       for (long long i = 0; i < m; i++) {         cin >> a[i].first >> a[i].second;         a[i].first--;         a[i].second--;       }       if (!bin(n, m)) {         return cout <<  -1 n , 0;       }       long long l = 1, r = m;       while (r - l > 1) {         long long mid = (l + r) / 2;         if (mid <= m && bin(n, mid))           r = mid;         else           l = mid;       }       if (bin(n, l))         cout << l <<   n ;       else         cout << r <<   n ;     }     return 0;   }   