#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, nuint_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; 
#define int long long
#define MOD 1000000007
#define what_is(x) cerr << #x << " is " << x << endl;
#define loop(i,a,n) for(int i=a;i<n;i++)
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, szof(x))
#define sortall(x) sort(aint(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626 
 	//https://www.youtube.com/playlist?list=PLWPirh4EWFpGeQoTYL5YpzBz8Gjw-sxJb
	//https://www.youtube.com/watch?v=pCvZtjoRq1I
	//https://leetcode.com/problems/word-search-ii/
	//https://leetcode.com/problems/numbers-at-most-n-given-digit-set/
	//https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv/
	//https://leetcode.com/problems/kth-smallest-number-in-multiplication-table/
	//https://leetcode.com/problems/find-k-pairs-with-smallest-sums/
	//https://leetcode.com/problems/numbers-with-repeated-digits/
	//https://leetcode.com/problems/lfu-cache/	
	//https://wordpresscom77092.wordpress.com/2018/08/28/spoj-cantor/
	//https://www.spoj.com/problems/TAP2012C/en/
	//https://codeforces.com/gym/100886/problem/G
	//https://www.codechef.com/problems/DIGIMU
	//https://leetcode.com/problems/k-th-smallest-prime-fraction/	
	//https://www.youtube.com/watch?v=fvPddKyHxpQ&list=PL6n9fhu94yhXcztdLO7i6mdyaegC8CJwR&index=2&t=0s
 	//https://codeforces.com/blog/entry/15296
	//https://leetcode.com/problems/redundant-connection-ii/
 	//https://leetcode.com/problems/delete-columns-to-make-sorted-iii/
 	//https://leetcode.com/problems/find-and-replace-in-string/
	//https://leetcode.com/problems/text-justification/
	//https://leetcode.com/problems/palindrome-pairs/
	//https://leetcode.com/problems/smallest-subsequence-of-distinct-characters/
	//https://leetcode.com/problems/shortest-path-visiting-all-nodes/
	//https://leetcode.com/problems/valid-permutations-for-di-sequence/
	//https://leetcode.com/problems/binary-tree-cameras/
	//https://leetcode.com/problems/minimum-cost-to-merge-stones/
 	//https://leetcode.com/problems/numbers-with-repeated-digits/
	//https://leetcode.com/problems/can-i-win/
	//https://leetcode.com/problems/out-of-boundary-paths/

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int, int> pt;

vector<int> edges[1010];
signed main() {
 
	fastio();
	//#define LOCAL_DEFINE	
	#ifdef LOCAL_DEFINE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	//https://medium.com/@maneesha.wijesinghe1/what-happens-when-you-type-an-url-in-the-browser-and-press-enter-bb0aa2449c1a
	//https://leetcode.com/problems/sort-items-by-groups-respecting-dependencies/
		//https://leetcode.com/problems/minimum-moves-to-reach-target-with-rotations/

	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int u,v;
		cin>>u>>v;
		edges[u].pb(v);
	}
	vector<int> ans;

	for(int i=1;i<=n;i++)
	{
		queue<int> q;
		vector<int> parent(n+10,0);
		for(auto itr:edges[i])
		{
			q.push(itr);
			parent[itr]=i;
		}
		while(!q.empty())
		{
			int v=q.front();
			q.pop();

			if(v==i)
			{
				vector<int> res;
				res.push_back(i);
				v=parent[v];
				while(i!=v)
				{
					res.push_back(v);
					v=parent[v];
					
				}
				if(ans.size()>res.size() || ans.empty())
					ans=res;
			}
			for(auto itr:edges[v])
			{
				if(!parent[itr])
				{
					parent[itr]=v;
					q.push(itr);
				}
			}
		}

	}
	if(ans.empty())
	{
		cout<<-1;
		return 0;
	}
	cout<<ans.size()<<endl;
	for(int i=0;i<ans.size();i++)
	{
		cout<<ans[i]<<endl;
	}
 	return 0;
}
 

Measured memory_bytes: 512