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

#define pb push_back

using ll = long long;

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int n, m; cin >> n >> m;
    vector<vector<int>> g(n);
    for (int i = 0; i < m; ++i) {
        int u, v; cin >> u >> v;
        --u, --v;
        g[u].pb(v);
    }
    vector<int> ans;
    for (int u = 0; u < n; ++u) {
        vector<int> par(n, -1);
        queue<int> q;
        for (int v : g[u]) {
            par[v] = u;
            q.push(v);
        }
        while (!q.empty()) {
            int cur = q.front();
            q.pop();
            if (cur == u) {
                vector<int> take;
                int x = par[u];
                while (x != u) {
                    take.pb(x);
                    x = par[x];
                }
                take.pb(u);
                if (ans.size() == 0 || take.size() < ans.size()) ans = take;
                break;
            }
            for (int nxt : g[cur]) {
                if (par[nxt] == -1) {
                    q.push(nxt);
                    par[nxt] = cur;
                }
            }
        }
    }
    if (ans.size()) {
        cout << ans.size() << "\n";
        for (int u : ans) cout << u + 1 << "\n";
    } else {
        cout << -1 << "\n";
    }
}