#include #include using namespace std; namespace mp = boost::multiprecision; int main(){ int N,K; cin>>N>>K; vector> edges(K+N,vector(2)); vector used(N); for(int i=0;i>r>>c; used[c-1]=1; edges[i]={r-1,c-1}; } int pointer=K; for(int i=0;i value(N+1,-1); vector before(N+1); vector> front(N+1,vector(0)); vector> parent(N+1,vector(0)); for(vector i:edges){ ++before[i[1]]; front[i[0]].push_back(i[1]); parent[i[1]].push_back(i[0]); } queue q; q.push(N); while(!q.empty()){ int p=-1; for(int i:parent[q.front()]){ p=max(p,value[i]); } value[q.front()]=p+1; for(int i:front[q.front()]){ --before[i]; if(!before[i]){ q.push(i); } } q.pop(); } int ans=0; for(int i=0;i