#include using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x>N>>K; FOR(i,N) R[i]=i; while(K--) { cin>>x>>y; swap(R[x-1],R[y-1]); } FOR(i,N) rev[R[i]]=i, A[0][i]=i; FOR(x,10000) { int cur=x%2,tar=cur^1; FOR(i,N) A[tar][i]=A[cur][rev[i]]; int ok=1; FOR(i,N) if(A[tar][i]!=i) ok=0; if(ok==1) return _P("%d\n",x+1); } } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); solve(); return 0; }