#include #include #include using namespace atcoder; using mint = modint998244353; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000001 int main(){ int N,M; cin>>N>>M; vector A(M),B(M); vector> E(N); rep(i,M){ cin>>A[i]>>B[i]; A[i]--;B[i]--; E[A[i]].push_back(B[i]); } rep(i,N){ vector visited(N,false); visited[i] = true; queue Q; Q.push(i); while(Q.size()>0){ int u = Q.front(); Q.pop(); rep(j,E[u].size()){ int v = E[u][j]; if(visited[v])continue; visited[v] = true; Q.push(v); } } rep(j,N){ if(!visited[j]){ cout<<-1< color(N,-1); stack Q; Q.push(0); color[0] = 0; bool f0 = false,f1 = false; while(Q.size()>0){ int u = Q.top(); Q.pop(); rep(i,E[u].size()){ int v = E[u][i]; if(color[v]==-1){ color[v] = color[u]^1; Q.push(v); } else{ if(color[u]!=color[v])continue; if(color[u]==0)f0=true; else f1=true; } } } if(!f0||!f1){ cout<<-1<