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

constexpr const int maxn = 1024;
vector<int> adj[maxn], dag[maxn];
int die[maxn], deg[maxn];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n, m;
	cin >> n >> m;
	while (m--) {
		int a, b;
		cin >> a >> b;
		adj[a].push_back(b);
		++deg[b];
	}
	vector<int> topo;
	for (int u = 1; u <= n; ++u) if (!deg[u]) topo.push_back(u);
	for (int i = 0; i != int(topo.size()); ++i) for (int u : adj[topo[i]]) if (!--deg[u]) topo.push_back(u);
	if (int(topo.size()) == n) return cout << -1 << endl, 0;
	for (int i = 1; i <= n; ++i) {
		die[i] = 1;
		vector<int> node;
		memset(deg, 0, maxn << 2);
		for (int u = 1; u <= n; ++u) dag[u].resize(0);
		for (int u = 1; u <= n; ++u) if (!die[u]) {
			node.push_back(u);
			for (int v : adj[u]) if (!die[v]) dag[u].push_back(v);
			for (int v : dag[u]) ++deg[v];
		}
		topo.resize(0);
		for (int u : node) if (!deg[u]) topo.push_back(u);
		for (int j = 0; j != int(topo.size()); ++j) for (int u : dag[topo[j]]) if (!--deg[u]) topo.push_back(u);
		if (topo.size() == node.size()) die[i] = 0;
	}
	vector<int> res;
	for (int i = 1; i <= n; ++i) if (!die[i]) res.push_back(i);
	cout << res.size() << endl;
	for (int ans : res) cout << ans << '\n';
}
