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

#define int long long

int n,m;
vector<int> ans;
int ee,h[100005],nex[100005],to[100005];
int vis[100005],in[100005],top,sk[100005];
int g[1005][1005];

void addedge(int x,int y)
{
	nex[++ee] = h[x];
	to[ee] = y;
	h[x] = ee;
}

void dfs(int x)
{
	vis[x] = true;
	sk[++top] = x;
	in[x] = true;
	for(int i=h[x];i;i=nex[i])
	{
		if(in[to[i]])
		{
			do{
				ans.push_back(sk[top]);
			}while(sk[top--]!=to[i]);
			cout<<ans.size()<<endl;
			for(int i=0;i<ans.size();i++)
				cout<<ans[i]<<endl;
			exit(0);
		}
		else if(!vis[to[i]])
			dfs(to[i]);
	}
	in[x] = false;
	top--;
}

signed main()
{
	cin>>n>>m;
	for(int i=1,x,y;i<=m&&cin>>x>>y;i++)
		addedge(x,y), g[x][y] = 1;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(g[i][j] && g[j][i])
				return cout<<2<<endl<<i<<endl<<j<<endl, 0;
	for(int i=1;i<=n;i++)
		if(!vis[i])
			dfs(i);
	puts("-1");
	
	return 0;
}