#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define bug1( x ) {cerr << (#x) <<"="<< x << endl;}
#define bug2( x , y ) {cerr << (#x) <<"="<< (x) << "    " << (#y) << "="<< (y) << endl;}
#define bug3( x , y , z ) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl;}
#define bug4( x , y , z , w) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl;}
#define bug5( x , y , z , w ,p) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << endl;}
#define bug6( x , y , z , w ,p , q) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << "    " << (#q) <<"="<< q << endl;}
#define bugn( x , n ) {cerr << (#x) <<":";for(int i=0;i<n;i++)cerr << x[i] <<"  "; cerr << endl;}
#define bugnm( x , n , m ) {cerr << (#x)<<endl;for(int i=0;i<n;i++){cerr << "Row #" << i<< ":";for(int j=0;j<m;j++)cerr << x[i][j] << "   ";cerr << endl;}}
typedef long long ll;
typedef long double ld;
using namespace std;


const int maxn = 1005, maxm = 2005;
vector<pair<int,int>>g[maxn],gr[maxn];
vector<int>vis(maxn),alive(maxn),tpl,cmp;
int n,m;
void dfs1(int u){
	vis[u]=1;
	for(auto [v,i]:gr[u]){
		if( !vis[v] ){
			dfs1(v);
		}
	}
	tpl.push_back(u);
}
void dfs2(int u){
	vis[u]=1;
	cmp.push_back(u);
	for(auto [v,i]:g[u]){
		if( !vis[v] ){
			dfs2(v);
		}
	}
}
int32_t main(){
	IOS
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int u,v;cin>>u>>v;
		g[u].push_back({v,i});
		gr[v].push_back({u,i});
	}
	for(int i=1;i<=n;i++){
		if( !vis[i] ){
			dfs1(i);
		}
	}
	fill(vis.begin(),vis.end(),0);
	for(int i=0;i<n;i++){
		int u = tpl[n-i-1];
		if( !vis[u] ){
			dfs2(u);
			if( cmp.size() > 1u ){
				for(auto u:cmp){
					alive[u]=1;
				}
				vector<vector<int>>dis(n+1,vector<int>(n+1,1e18));
				vector<vector<int>>use(n+1,vector<int>(n+1,0000));
				vector<vector<int>>par(n+1,vector<int>(n+1,0000));
				for(auto s:cmp){
					vector<int>inq(n+1);
					queue<pair<int,int>>q;
					q.push({s,0});
					inq[s]=1;
					while( q.size() ){
						int u = q.front().first;
						int d = q.front().second;
						q.pop();inq[u]=0;
						for(auto [v,i]:g[u]){
							if( alive[v] && dis[s][v] > d + 1){
								dis[s][v] = d + 1;
								par[s][v] = u;
								use[s][v] = i;
								if( !inq[v] ){
									q.push({v,dis[s][v]});
									inq[v]=1;
								}
							}
						}
					}
				}
				int root = cmp[0];
				for(auto s:cmp){
					//bug2(u,dis[s][s]);
					if( dis[s][s] < dis[root][root] ){
						root = s;
					}
				}
				set<int>st;
				int cur = root;
				list<int>ans;
				// used edges:::::
				/*while( !st.count(use[root][cur]) ){
					ans.push_front(use[root][cur]);
					st.insert(use[root][cur]);
					cur = par[root][cur];
				}*/
				// used nodes:::::
				while( !st.count(par[root][cur]) ){
					ans.push_front(par[root][cur]);
					st.insert(par[root][cur]);
					cur = par[root][cur];
				}
				cout << ans.size() << endl;
				for(auto e:ans){
					cout << e <<" ";
				}
				cout << endl;
				return 0;
			}
			cmp.clear();
		}
	}
	cout <<-1 << endl;
	
}
/*
 * long long or int?
 * index out of bound?
 * Tested on own test case?corner?
 * Make more general solution.
 * Read Read Read Read ....
 */


Measured memory_bytes: 27376