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

typedef vector<vector<int>> UnWeightedGraph;

template< typename G >
struct StronglyConnectedComponents {
    const G &g;
    UnWeightedGraph gg, rg;
    vector< int > comp, order, used;

    StronglyConnectedComponents(G &g) : g(g), gg(g.size()), rg(g.size()), comp(g.size(), -1), used(g.size()) {
        for(int i = 0; i < g.size(); i++) {
            for(auto e : g[i]) {
                gg[i].emplace_back((int) e);
                rg[(int) e].emplace_back(i);
            }
        }
    }

    int operator[](int k) {
        return comp[k];
    }

    void dfs(int idx) {
        if(used[idx]) return;
        used[idx] = true;
        for(int to : gg[idx]) dfs(to);
        order.push_back(idx);
    }

    void rdfs(int idx, int cnt) {
        if(comp[idx] != -1) return;
        comp[idx] = cnt;
        for(int to : rg[idx]) rdfs(to, cnt);
    }

    void build(UnWeightedGraph &t) {
        for(int i = 0; i < gg.size(); i++) dfs(i);
        reverse(begin(order), end(order));
        int ptr = 0;
        for(int i : order) if(comp[i] == -1) rdfs(i, ptr), ptr++;

        t.resize(ptr);
        for(int i = 0; i < g.size(); i++) {
            for(auto &to : g[i]) {
                int x = comp[i], y = comp[to];
                if(x == y) continue;
                t[x].push_back(y);
            }
        }
    }
};

vector<vector<int> > gomi;

vector<int> subgraph[1010];

vector<int> g[1010];

int start = -1;

set<pair<int, int> > go;

int yta[1010];
int used[1010] = {};

void dfs(int i, int cnt){

    if(used[i]){
        start = i;
        return;
    }
    used[i] = 1;

    dfs(g[i][0], cnt+1);

    if(start == -1){
        return;
    }

    yta[i] = cnt;
    go.insert({cnt, i});

    if(start == i){
        start = -1;
    }

    return;
}

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int> > graph(n);

    pair<int, int> e[2010];
    for(int i = 0;i < m;i++){
        int s, t;
        cin >> s >> t;
        s--;
        t--;
        e[i] = {s, t};
        graph[s].push_back(t);
    }

    StronglyConnectedComponents<vector<vector<int>>> scc(graph);
    scc.build(gomi);

    int use = -1;
    for(int i = 0;i < n;i++){
        subgraph[scc[i]].push_back(i);
        if(subgraph[scc[i]].size() > 1){
            use = scc[i];
        }
    }

    if(use == -1){
        cout << -1 << endl;
        return 0;
    }



    vector<pair<int, int> > ydk;
    for(int i = 0;i < m;i++){
        if(scc[e[i].first] == use && scc[e[i].second] == use){
            g[e[i].first].push_back(e[i].second);
            ydk.push_back(e[i]);
        }
    }

    dfs(subgraph[use][0], 0);


    for(int i = 0;i < ydk.size();i++){
        int s = ydk[i].first;
        int t = ydk[i].second;
        auto st = go.find({yta[s], s});
        auto en = go.find({yta[t], t});

        if(st != go.end() && en != go.end() && st != en){
            st++;
            if(st == go.end()){
                st = go.begin();
            }

            while(st != go.find({yta[t], t})){
                go.erase(st++);
                if(st == go.end()){
                    st = go.begin();
                }
            }
        }
    }

    cout << go.size() << endl;
    for(auto itr = go.begin(); itr != go.end(); itr++){
        cout << (*itr).second  + 1<< endl;
    }

    return 0;
}





Measured memory_bytes: 640