#include <bits/stdc++.h>
using namespace std;
const int MX = 1e3+2;
vector<int> adj[MX];
int seen[MX], depth[MX];
int prv[MX], st, anslen = 10000;
vector<int> ans;
bool ok;
void dfs(int i) {
	seen[i] = 1;
	for(int a: adj[i]) {
		if(!seen[a]) {
			prv[a] = i;
			depth[a] = depth[i] + 1;
			dfs(a);
		} else if(seen[a] == 1) {
			if(depth[i] - depth[a] < anslen) {
				anslen = depth[i] - depth[a];
				ans = {};
				int cur = i;
				while(cur != a) {
					ans.push_back(cur);
					cur = prv[cur];
				}
				ans.push_back(a);
			}
		}
	}
	seen[i] = 2;
}
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n, m;
	cin >> n >> m;
	for(int i=0; i<m; i++) {
		int a, b;
		cin >> a >> b;
		adj[a].push_back(b);
	}
	for(int i=1; i<=n; i++) {
		st = i;
		memset(seen, 0, sizeof seen);
		memset(depth, 0, sizeof depth);
		dfs(st);
	}
	if(anslen == 10000)
		return !(cout << -1);
	cout << ans.size() << '\n';
	for(int a: ans)
		cout << a << ' ';
}