
#include <bits/stdc++.h>
#define pb push_back
#define N 1005

using namespace std;

int n, m;
vector<int> G[N];
bool visit[N], ok = false;
int mini = (1<<30), nodo, d[N], p[N];

void bfs( int u ){
	visit[u] = true;
	queue <int> Q;
	d[u] = 0;
	Q.push(u);
	while(!Q.empty()){
		int q = Q.front();
		Q.pop();
		for( int i = 0; i < G[q].size(); i++ ){
			int v = G[q][i];
			if( v == u ){
				ok = true;
				if( mini > d[q] ){
					mini = d[q]+1;
					nodo = u;
				}
				return;
			}
			
			if( !visit[v] ){
				Q.push(v);
				d[v] = d[q]+1;
				visit[v] = true;
			}
		}	
	}
}


int bfs2( int u ){
	visit[u] = true;
	p[u] = -1;
	queue <int> Q;
	d[u] = 0;
	Q.push(u);
	while(!Q.empty()){
		int q = Q.front();
		Q.pop();
		for( int i = 0; i < G[q].size(); i++ ){
			int v = G[q][i];
			if( v == u ){
				return q;
			}
			
			if( !visit[v] ){
				Q.push(v);
				p[v] = q;
				visit[v] = true;
			}
		}	
	}
}


int main( void ){
	scanf("%d%d",&n,&m);
	for( int i = 0; i < m; i++ ){
		int x, y;
		scanf("%d%d",&x,&y);
		x--; y--;
		G[x].pb(y);
	}
	
	for( int i = 0; i < n; i++ ){
		memset( visit, false, sizeof visit );
		memset( d, -1, sizeof d );
		bfs(i);
	}
	if(!ok) puts("-1");
	else{
		cout << mini << endl;
		memset( visit, 0, sizeof visit );
		memset( p, -1, sizeof p );
		int z = bfs2(nodo);
		while( p[z] != -1 ){
			cout << z+1 << endl;
			z = p[z];
		}
		cout << z+1 << endl;
	}

	return 0;
}



