#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #define int long long

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

typedef pair<int, int> pint;

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front

#define MOD (1000 * 1000 * 1000 + 7)
#define MAX 10000000

vector<int> bfs(int N, vector<vector<int>> &edges, int from) {
    queue<int> que;
    vector<int> d(N, MAX);
    que.push(from);
    bool is_end = false;

    while (!que.empty()) {
        int now = que.front();
        que.pop();

        int next_d = (d[now] + 1) % MAX;
        for (int to: edges[now]) {
            if (d[to] < next_d) continue;
            d[to] = next_d;
            que.push(to);

            if (to == from) {
                is_end = true;
                break;
            }
        }

        if (is_end) break;
    }

    return d;
}

vector<int> path(int N, int from, vector<int> d, vector<vector<int>> &edges_rev) {
    vector<int> p;

    int now = from;
    p.pb(from);
    while (true) {
        if (d[now] == 1) break;

        for (int to: edges_rev[now]) {
            if (d[to] == d[now] - 1) {
                now = to;
                p.pb(now);
                break;
            }
        }
    }

    return p;
}

void remake(int N, vector<int> v,
    vector<vector<int>> &edges,
    vector<vector<int>> &_edges, vector<vector<int>> &_edges_rev) {

    vector<int> v_map(N, 0);
    for (int i: v) v_map[i] = 1;

    for (int from: v) {
        for (int to: edges[from]) {
            if (v_map[to] == 0) continue;

            _edges[from].pb(to);
            _edges_rev[to].pb(from);
        }
    }
}

vector<int> solve(int N, vector<vector<int>> &edges, vector<vector<int>> &edges_rev) {
    vector<int> ans;

    REP (from, N) {
        vector<int> d = bfs(N, edges, from);

        if (d[from] == MAX) continue;

        ans = path(N, from, d, edges_rev);

        // cout << "ans" << endl;
        // for (int i: ans) {
        //     cout << i << endl;
        // }

        break;
    }

    if (SZ(ans) == 0) return ans;

    vector<vector<int>> _edges(N, vector<int>());
    vector<vector<int>> _edges_rev(N, vector<int>());
    remake(N, ans, edges, _edges, _edges_rev);

    // cout << "_edges" << endl;
    // REP (i, N) {
    //     for (int to: _edges[i]) {
    //         cout << i << " " << to << endl;
    //     }
    // }

    while (true) {
        int now_distance = SZ(ans);

        vector<int> _ans;
        for (int from: ans) {
            vector<int> d = bfs(N, _edges, from);
            if (d[from] == now_distance) continue;

            _ans = path(N, from, d, _edges_rev);
            break;
        }

        if (SZ(_ans) == 0) break;

        ans = _ans;

        vector<vector<int>> __edges(N, vector<int>());
        vector<vector<int>> __edges_rev(N, vector<int>());
        remake(N, ans, _edges, __edges, __edges_rev);

        _edges = __edges;
        _edges_rev = __edges_rev;
    }

    return ans;
}

signed main() {
    int N, M;
    cin >> N >> M;

    vector<vector<int>> edges(N, vector<int>());
    vector<vector<int>> edges_rev(N, vector<int>());
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        a--; b--;

        edges[a].pb(b);
        edges_rev[b].pb(a);
    }

    vector<int> ans = solve(N, edges, edges_rev);

    if (SZ(ans) == 0) {
        cout << -1 << endl;
    } else {
        cout << SZ(ans) << endl;
        for (int i: ans) {
            cout << i + 1 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 640