#include #include #include #include #include #include #include #include #include #include #include using namespace std; template using pq = priority_queue, greater>; vector topological_sort(vector> &E){ int N = E.size(), C; vector deg(N), res; pq que; for (int i=0; i A, B; bool solve(int c){ vector> E(N); vector ans; for (int i=0; i> N >> Q; A.resize(Q); B.resize(Q); for (int i=0; i> A[i] >> B[i]; A[i]--; B[i]--; } if (!solve(Q)){ cout << -1 << endl; return 0; } r = Q; l = 0; while(r-l>1){ c = (r+l)/2; if (solve(c)) r=c; else l=c; } cout << r << endl; return 0; }