#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n, m;
	cin >> n >> m;

	vvl adj(n);
	while (m--) {
		ll a, b;
		cin >> a >> b;
		a--, b--;
		adj[a].pb(b);
	}
	
	vl res;
	FOR(s,0,n) {
		vl pred(n,-1);
		queue<ll> q;
		q.push(s);

		while (sz(q)) {
			ll i = q.front();
			q.pop();
			for (ll j: adj[i]) {
				if (j == s) {
					vl cur = {i};
					while (i != s) i = pred[i], cur.pb(i);
					if (sz(res) == 0 || sz(cur) < sz(res)) res = cur;
					while (sz(q)) q.pop();
					break;
				}
				if (pred[j] != -1) continue;
				pred[j] = i;
				q.push(j);
			}
		}
	}

	if (sz(res)) {
		cout << sz(res) << endl;
		for (ll x: res) cout << x+1 << endl;
	} else {
		cout << -1 << endl;
	}
}

