#include <bits/stdc++.h>
using namespace std;


int main() {
	int N, M;
	cin >> N >> M;
 
	vector<vector<int>> g(N);
	while (M--) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		g[a].push_back(b);
	}
	
	vector<int> cycle;
    for (int s = 0; s < N; s++) {  // Loop for all vertices; s as the starting vertex.
		vector<int> par(N, -1);
		queue<int> q;
		q.push(s);
 
		while (q.size()) {
			int i = q.front();
			q.pop();
			for (int j: g[i]) {
				if (j == s) {
					vector<int> cur = {i};
					while (i != s) i = par[i], cur.push_back(i);
					if (cycle.size() == 0 || cur.size() < cycle.size()) cycle = cur;
					while (q.size()) q.pop();
					break;
				}
				if (par[j] != -1) continue;
				par[j] = i;
				q.push(j);
			}
		}
	}
 
	if (cycle.size()) {
		cout << cycle.size() << endl;
		for (int x: cycle) cout << x + 1 << endl;
	} else {
		cout << -1 << endl;
	}

    return 0;
}
