#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pi pair<int,int>
#define ff first
#define ss second
#define boost ios_base::sync_with_stdio(false);cin.tie(nullptr)
#include "string"

const int N = 1001;
const int inf = 1e9;
int g[N][N];

void print(int n){
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++)
			cout<<g[i][j]<<" ";
		cout<<endl;
	}
}

int32_t main() { 
	boost;
	int n,m;
	cin>>n>>m;
	memset(g,1,sizeof g);
	vector<int>adj[n+1];
	for(int i=0,u,v;i<m;i++){
		cin>>u>>v;
		g[u][v] = 1;
		adj[u].push_back(v);
	}

	for(int k=1;k<=n;k++){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++)
				g[i][j] = min(g[i][j],g[i][k]+g[k][j]);
		}
	}
	int mx = g[1][1],root=1;
	for(int i=1;i<=n;i++){
		if(g[i][i]<mx){
			mx = g[i][i];
			root = i;
		}
	}

	if(mx > 2002){
		cout<<-1<<endl;
		return 0;
	}
	cout<<mx<<endl;
	for(int i=1;i<=mx;i++){
		cout<<root<<endl;
		for(int v:adj[root]){
			if(g[v][v] == mx){
				root = v;
				break;
			}
		}
	}
}	