#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

typedef long long ll;

const ll M = 4e18;

ll n, m, mn = M;
vector<ll> ve[1005];
vector<ll> ans;
vector<ll> now;
ll vv[1005];

void dfs(ll p)
{
    if(now.size() != 0 && p == now[0])
    {
        if(mn > now.size())
        {
            mn = now.size();
            ans = now;
        }
        return;
    }
    else if(vv[p]) return;
    if(now.size() > mn) return;
    vv[p] = true;
    now.push_back(p);
    for(ll i = 0; i < ve[p].size(); i++)
    {
        dfs(ve[p][i]);
    }
//    vv[p] = false;
    now.pop_back();
}

int main()
{
    scanf("%lld%lld", &n, &m);
    for(ll i = 0; i < m; i++)
    {
        ll u, v;
        scanf("%lld%lld", &u, &v);
        ve[u].push_back(v);
    }
    for(ll i = 1; i <= n; i++)
    {
        for(ll i = 1; i <= n; i++) vv[i] = false;
        dfs(i);
    }
    if(mn == M) printf("-1\n");
    else
    {
        printf("%lld\n", mn);
        for(ll i = 0; i < ans.size(); i++)
        {
            printf("%lld\n", ans[i]);
        }
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    ll n, m;
    cin >> n >> m;
    vector<vector<ll>> g(n), r(n);
    rep(i, m) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        r[b].push_back(a);
    }
    vector<ll> ans(n + 1);
    rep(i, n) {
        queue<ll> q;
        vector<ll> dist(n, LONG_LONG_MAX);
        vector<ll> prev(n, LONG_LONG_MAX);
        q.push(i);
        dist[i] = 0;
        while(!q.empty()) {
            ll now = q.front(); q.pop();
            rep(ii, sz(g[now])) {
                ll next = g[now][ii];
                if (dist[next] <= (dist[now] + 1)) continue;
                dist[next] = dist[now] + 1;
                prev[next] = now;
                q.push(next);
            }
        }
        vector<ll> tmp;
        q.push(i);
        tmp.push_back(i);
        while(!q.empty()) {
            ll now = q.front(); q.pop();
            ll mi = -1, mv = LONG_LONG_MAX;
            rep(ii, sz(r[now])) {
                ll next = r[now][ii];
                if (mv <= dist[next]) continue;
                mv = dist[next];
                mi = next;
            }
            if ((mv == LONG_LONG_MAX) || (mi == i)) break;
            tmp.push_back(mi);
            q.push(mi);
        }
        if ((sz(tmp) == 1) || (sz(tmp) >= sz(ans))) continue;
        reverse(tmp.begin() + 1, tmp.end());
        ans = tmp;
    }
    if (sz(ans) == (n + 1)) {
        cout << -1 << endl;
    }
    else {
        cout << sz(ans) << endl;
        rep(i, sz(ans)) cout << (ans[i] + 1) << endl;
    }
    return 0;
}
