#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 1; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

class Scc
{
    using Graph = std::vector<std::vector<int>>;
    int V, K;
    Graph G, rG;
    std::vector<int> vs;
    std::vector<bool> used;
    std::vector<int> cmp;
    void dfs(int cur)
    {
        used[cur] = true;
        for (const auto &v : G[cur])
        {
            if (!used[v])
                dfs(v);
        }
        vs.push_back(cur);
    }
    void rdfs(int cur, int k)
    {
        used[cur] = true;
        cmp[cur] = k;
        for (const auto &v : rG[cur])
        {
            if (!used[v])
                rdfs(v, k);
        }
    }

public:
    Scc(int _V) : V(_V), G(_V), rG(_V), used(_V, false), cmp(_V) {}
    void add_edge(int from, int to)
    {
        G[from].push_back(to);
        rG[to].push_back(from);
    }
    // SCCした後の頂点の対応関係(xor頂点数)を取得する
    pair<int, std::vector<int>> scc()
    {
        for (int i = 0; i < V; i++)
            used[i] = false;
        vs.clear();
        for (int v = 0; v < V; v++)
        {
            if (!used[v])
                dfs(v);
        }
        for (int i = 0; i < V; i++)
            used[i] = false;
        int k = 0;
        for (int i = (int)vs.size() - 1; i >= 0; i--)
        {
            if (!used[vs[i]])
                rdfs(vs[i], k++);
        }
        // 頂点数
        K = k;
        // cmp[i] := 頂点i がSCC後に属する強連結成分番号
        return make_pair(k, cmp);
    }
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    vector<vector<int>> g0(n);
    Scc scc(n);
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g0[a].push_back(b);
        scc.add_edge(a, b);
    }
    auto p = scc.scc();
    int k = p.first;
    auto v = p.second;
    if (k == n)
    {
        cout << -1 << endl;
        return 0;
    }
    vector<vector<int>> g(n);
    for (int i = 0; i < n; i++)
    {
        for (int nxt : g0[i])
        {
            if (v[i] == v[nxt])
                g[i].push_back(nxt);
        }
    }
    int ma = INF;
    vector<int> ret;
    for(int i=0;i<n;i++)
    {
        if(g[i].size()==0) continue;
        vector<int> d(n,INF), pre(n, -1);
        queue<int> que;
        d[i] = 0;
        que.push(i);
        while(!que.empty())
        {
            int cur = que.front();
            que.pop();
            for(auto nxt:g[cur])
            {
                if(nxt==i)
                {
                    d[nxt] = d[cur] + 1;
                    pre[nxt] = cur;
                    break;
                }
                if(d[nxt]!=INF) continue;
                d[nxt] = d[cur] + 1;
                pre[nxt] = cur;
                que.push(nxt);
            }
            if(d[i]!=0) break;
        }
        assert(d[i]!=0);
        if(d[i]<ma)
        {
            ma = d[i];
            ret.clear();
            int cur = pre[i];
            ret.push_back(cur);
            while(cur!=i)
            {
                cur = pre[cur];
                ret.push_back(cur);
            }
        }
    }
    cout << ret.size() << endl;
    for(auto r:ret) cout << r+1 << endl;
}


Measured memory_bytes: 512