//g++ 2.cpp -std=c++14 -O2 -I . #include using namespace std; #include using namespace atcoder; using ll = long long; using ld = long double; using vi = vector; using vvi = vector; using vll = vector; using vvll = vector; using vld = vector; using vvld = vector; using vst = vector; using vvst = vector; #define fi first #define se second #define pb push_back #define eb emplace_back #define pq_big(T) priority_queue,less> #define pq_small(T) priority_queue,greater> #define all(a) a.begin(),a.end() #define rep(i,start,end) for(ll i=start;i<(ll)(end);i++) #define per(i,start,end) for(ll i=start;i>=(ll)(end);i--) #define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end()) void dfs(vvi &g,vi &seen,int now,int par,int &flg){ seen[now]=1; for(int next:g[now]){ if(next==par){ flg=0; return; } dfs(g,seen,next,now,flg); } } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n,q; cin>>n>>q; vector> edge(q); rep(i,0,q){ int a,b; cin>>a>>b; a--; b--; edge[i]={a,b}; } int ng=0,ok=q+1; while(ok-ng>1){ int check=(ok+ng)/2; vvi g(n); rep(i,0,check){ auto [a,b]=edge[i]; g[a].emplace_back(b); } cerr<