#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 1e3 + 5;
const ll LINF = 1e18 + 5;
int n, m, pre[N];
vector <int> G[N], ans;
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> n >> m;
 	for(int i=1; i<=m; i++)
 	{
 		int u, v;
 		cin >> u >> v;
 		G[u].pb(v);
 	}
 	for(int i=1; i<=n; i++)
 	{
 		memset(pre+1, 0, n*sizeof(int));
 		queue <int> q;
 		for(int v : G[i])
 		{
 			pre[v] = i;
 			q.push(v);
 		}
 		while(sz(q))
 		{
 			int u = q.front(); q.pop();
 			if(u==i)
 			{
 				vector <int> loop;
 				int x = pre[u];
 				while(x!=i)
 				{
 					loop.pb(x);
 					x = pre[x];
 				}
 				loop.pb(x);
 				if(!sz(ans) || sz(loop)<sz(ans)) swap(loop, ans);
 				break;
 			}
 			for(int v : G[u])
 			{
 				if(!pre[v])
 				{
 					pre[v] = u;
 					q.push(v);
 				}
 			}
 		}
 	}
 	if(sz(ans))
 	{
 		cout << sz(ans) << '\n';
 		reverse(all(ans));
 		for(int x : ans) cout << x << '\n';
 	}
 	else cout << -1 << '\n';
	return 0;
}
