#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;

int n, m, a, b, vt[1005];
vector<int> gr[1005], tmp, ans;

void dfs(int p) {
	tmp.push_back(p);
	vt[p] = 1;
	for(int x:gr[p]) {
		if(x == tmp[0]) {
			if(ans.empty() || tmp.size() < ans.size()) ans = tmp;
		} else if (!vt[x]) {
			dfs(x);
		}
	}
	tmp.pop_back();
}

int main() {
	cin >> n >> m;
	while(m--) {
		cin >> a >> b;
		gr[a].push_back(b);
	}
	for(int i=1; i<=n; i++) {
		memset(vt, 0, sizeof(vt));
		tmp.clear();
		dfs(i);
	}
	if(ans.empty()) {puts("-1"); return 0;}
	cout << ans.size() << endl;
	for(auto x:ans) cout << x << endl;
	return 0;
}
