#include<cstdio>
#include<vector>
using namespace std;
const int MAXN = 1000;
vector<int>G[MAXN + 5];
bool tag[MAXN + 5], vis[MAXN + 5], flag;
int stk[MAXN + 5], tp, val;
void dfs(int x) {
	stk[++tp] = x, vis[x] = tag[x] = true;
	for(int i=0;i<G[x].size();i++) {
		int p = G[x][i];
		if( !vis[p] ) dfs(p);
		else if( tag[p] )
			val = p, flag = true;
		if( flag ) return ;
	}
	stk[tp--] = 0, vis[x] = false;
}
int nxt[MAXN + 5];
vector<int>ans;
int main() {
	int N, M; scanf("%d%d", &N, &M);
	for(int i=1;i<=M;i++) {
		int A, B; scanf("%d%d", &A, &B);
		G[A].push_back(B);
	}
	for(int i=1;i<=N;i++)
		if( !tag[i] ) {
			dfs(i);
			if( flag ) break;
		}
	if( !flag ) {
		puts("-1");
		return 0;
	}
	int pos;
	for(int i=1;i<=tp;i++)
		if( stk[i] == val ) pos = i;
	nxt[stk[tp]] = val;
	for(int i=pos;i<tp;i++)
		nxt[stk[i]] = stk[i+1];
	for(int i=1;i<=N;i++) {
		if( !nxt[i] ) continue;
		for(int j=0;j<G[i].size();j++) {
			int x = G[i][j];
			if( !nxt[x] ) continue;
			int p = i, q = nxt[i];
			while( q != x ) {
				int r = nxt[q];
				nxt[p] = r;
				nxt[q] = 0;
				q = r;
			}
		}
	}
	int x;
	for(int i=1;i<=N;i++)
		if( nxt[i] ) x = i;
	int p = x;
	do {
		ans.push_back(p);
		p = nxt[p];
	}while( p != x );
	printf("%d\n", ans.size());
	for(int i=0;i<ans.size();i++)
		printf("%d\n", ans[i]);
}