// Marcin Knapik
#include<bits/stdc++.h>
#include<unistd.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
 
typedef long double             ld;
typedef long long               ll;
typedef unsigned long long      ull;
typedef pair<ll, ll>            pll;
typedef pair<int, int>          ii;
typedef vector<int>             vi;
typedef vector<ii>              vii;
typedef vector<vi>              vvi;
typedef vector<vector<ii>>      vvii;
typedef vector< ll >            vll;
typedef vector< pll >           vpll;
 
#define boost                   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(a)                   (int)(a).size()
#define pb                      push_back
#define all(c)                  (c).begin(), (c).end()
#define rall(c)                 (c).rbegin(), (c).rend()
#define REP(i, a, b)            for (int i = (a); i <= (b); i++)
#define FOR(i, a)               for (int i = 0; i < (a); i++)
#define TRAV(i, n)              for(auto&i:n)
#define beg(x)                  (*(x.begin()))
#define re(x)                   int x; cin >>x;   
#define f                       first
#define s                       second
 
template <class T> inline bool setmin(T &a, T b){if (a > b)return a = b, 1;return 0;}
template <class T> inline bool setmax(T &a, T b){if (a < b)return a = b, 1;return 0;}
 
template<class T> inline T fast(T a,T b,T mod) {ll res = 1; while(b){if(b&1) res = (res*a)%mod;a = (a*a)%mod;b >>= 1;}return res;}
template<class T> inline T russian(T a, T b, T mod) {ll res = 0; while(b){if(b&1) res = (res + a)%mod; a = (a+a)%mod; b>>=1;}return res;}
template <class T> istream &operator>>(istream &os, vector<T> &container){for (auto &u : container)os >> u;return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &container){for (auto &u : container)os << u << " ";return os;}
template<typename T> inline T gcd(T a, T b) { while (b)swap(a %= b, b); return a; }
 
const ll T = 1 << 20;
const int INF = 1e9 + 7;
// const ll mod = 998244353;
const ll BIG_INF = 1e18 + 7;
const ll  N = 1e6+7;
const int LOG = 17;
 
ll n, m, q;

vvi G(N);
int odw[1007][1007];
int przodek[1007][1007];
int kraw[1007][1007];

int na_cyklu[N];
int odw2[N];

void bfs(int start){
	queue<pair<int, int>> kol;
	kol.push({start, 0});
	odw[start][0] = 1;
	while(sz(kol)){
		auto akt = kol.front();
		kol.pop();
		if(akt.f == start && akt.s > 0){
			vi ans;
			int temp = start;
			int odl = akt.s;
			while(1){
				ans.pb(temp);
				// cout << temp << ' ' << odl << ' ' << przodek[temp][odl] <<endl;;
				//ans.pb(kraw[przodek[temp][odl]][temp]);
				temp = przodek[temp][odl--];
				if(temp == start)
					break;
			}
			sort(all(ans));
			cout << sz(ans) << '\n';
			for(int i = 0 ; i < sz(ans); i++){
				cout << ans[i] << '\n';
			}
			exit(0);
		}
		TRAV(u, G[akt.f]){
			if(odw[u][akt.s+1]){
				continue;
			}
			odw[u][akt.s+1]=1;
			przodek[u][akt.s+1] = akt.f;
			kol.push({u, akt.s+1});
		}
	}
}

void dfs(int start){
	odw2[start] = 1;
	TRAV(u, G[start]){
		if(odw2[u] == 2){

		}
		else if(odw2[u] == 1){
			na_cyklu[start] = 1;
		}
		else
			dfs(u);
	}
	odw2[start] = 2;
}

signed main(){
	boost;
	srand(time(0) + getpid());

	cin >> n >> m;
	FOR(i, m){
		int a, b;
		cin >> a >> b;
		G[a].pb(b);
		kraw[a][b] = i+1;
		if( kraw[a][b] && kraw[b][a]){
			cout << 2 << '\n';
			cout << min(a, b) << '\n';
			cout << max(a, b) << '\n';
			exit(0);
		}
	}
	for(int i = 1; i <= n; i++){
		if(!odw2[i])
			dfs(i);
	}
	vi na;
	for(int i = 1; i <= n; i++){
		if(na_cyklu[i]){

			// cout << i << ' ' << "LOL " << endl;
			//bfs(i);
			na.pb(i); 
		}
	}
	if(sz(na)){
		if(rand()&1)
			random_shuffle(all(na));
		bfs(na[0]);
	}

	cout << -1 << '\n';
}

Measured memory_bytes: 39168