#include using namespace std; int main(){ int N, M; cin >> N >> M; vector> E1(N), E2(N); vector> E(N); for (int i = 0; i < M; i++){ int A, B; cin >> A >> B; A--; B--; E1[A].push_back(B); E2[B].push_back(A); E[A].push_back(B); E[B].push_back(A); } vector used1(N, false); used1[0] = true; queue Q1; Q1.push(0); while (!Q1.empty()){ int v = Q1.front(); Q1.pop(); for (int w : E1[v]){ if (!used1[w]){ used1[w] = true; Q1.push(w); } } } vector used2(N, false); used2[0] = true; queue Q2; Q2.push(0); while (!Q2.empty()){ int v = Q2.front(); Q2.pop(); for (int w : E2[v]){ if (!used2[w]){ used2[w] = true; Q2.push(w); } } } bool ok = false; vector c(N, -1); c[0] = 0; queue Q; Q.push(0); while (!Q.empty()){ int v = Q.front(); Q.pop(); for (int w : E[v]){ if (c[w] == -1){ c[w] = 1 - c[v]; Q.push(w); } else if (c[v] == c[w]){ ok = true; } } } for (int i = 0; i < N; i++){ if (!used1[i]){ ok = false; } } for (int i = 0; i < N; i++){ if (!used2[i]){ ok = false; } } if (M <= N + 1){ ok = false; } if (!ok){ cout << -1 << endl; } else { assert(false); } }