#include using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) template bool chmax(T &a, const T &b) { if(a bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;} //------------------------------------------------------- int N,M; vector E[2][1010]; int ok[2020][2]; string S; int id[1010][1010]; int cnt[1010][1010]; vector R[1010]; int vis[1010]; vector path; void dfs(int cur,int start,int depth) { if(cur==start&&depth) { R[depth]=path; return; } if(vis[cur]!=-1) return; vis[cur]=depth; path.push_back(cur); FORR(e,E[0][cur]) dfs(e,start,depth+1); path.pop_back(); vis[cur]=-2; } void solve() { int i,j,k,l,r,x,y; string s; cin>>N>>M; MINUS(id); FOR(i,M) { cin>>x>>y; x--,y--; E[0][x].push_back(y); E[1][y].push_back(x); id[x][y]=i; } S=string(M,'R'); ok[0][0]=ok[0][1]=1; queue Q; Q.push(0); Q.push(1); while(Q.size()) { int cur=Q.front()/2; int id=Q.front()%2; Q.pop(); FORR(e,E[id][cur]) if(ok[e][id]==0) { ok[e][id]=1; Q.push(e*2+id); } } FOR(i,N) if(ok[i][0]==0||ok[i][1]==0) return _P("-1\n"); FOR(i,N) { MINUS(vis); dfs(i,i,0); } FOR(y,N+1) FOR(x,y) if(__gcd(x,y)==1&&R[x].size()&&R[y].size()) { for(i=0;i