#include <iostream>
#include <queue>
#include <vector>

using namespace std;

using Pii = pair<int, int>;

constexpr int N_MAX = 1123;

int n, m;
vector<int> graph[N_MAX];
vector<Pii> edges;
vector<bool> used(N_MAX, false), in_history(N_MAX, true);
deque<int> history;

inline void show_history() {
    int l = history.size();
    cout << l << endl;
    for(int i=0;i<l;++i) {
        cout << history[i]+1 << endl;
    }
}

inline bool check() {
    vector<int> indeg(N_MAX, 0), outdeg(N_MAX, 0);
    for(int i: history) {
        for(int j: graph[i]) {
            ++outdeg[i];
            ++indeg[j];
        }
    }

    for(int x: history) {
        if(outdeg[x] != 1 || indeg[x] != 1) return false;
    }
    return true;
}

inline bool dfs(int node) {
    used[node] = true;
    in_history[node] = true;
    history.push_back(node);
    for(int child: graph[node]) {
        if(in_history[child]) {
            while(history.front() != child) {
                in_history[history.front()] = false;
                history.pop_front();
            }
            return true;
        }
        if(dfs(child)) return true;
    }
    history.pop_back();
    in_history[node] = false;
    return false;
}

int main() {
    std::ios::sync_with_stdio(false); cin.tie(nullptr);
    cin >> n >> m;
    int a, b;
    for(int i=0;i<m;++i){
        cin >> a >> b;
        --a; --b;
        graph[a].push_back(b);
        edges.emplace_back(a, b);
    }

    // 閉路探し (閉路がなければ終わり)
    {
        int i = 0;
        for(;i<n;++i) {
            if(used[i]) continue;
            in_history = vector<bool>(N_MAX, false);
            if(dfs(i)) break;
        }
        if(i == n) {
            cout << -1 << endl;
            return 0;
        }
    }

    // 閉路縮約
    Pii e = {0, -1};
    while(e.first != -1 && !check()) {
        // いらないエッジを消す
        for(int i=0;i<n;++i) graph[i].clear();
        for(Pii e: edges) {
            if(in_history[e.first] && in_history[e.second]) {
                graph[e.first].push_back(e.second);
            }
        }

        // 注目する辺を選ぶために，閉路を作っている辺をチェックする
        vector<bool> selected[n];
        for(int i=0;i<n;++i) {
            selected[i].assign(graph[i].size(), false);
        }
        int n_history = history.size();
        for(int i=0;i<n_history;++i) {
            int a = history[i], b = history[(i+1)%n_history];
            for(int j=0;j<graph[a].size();++j) {
                if(graph[a][j] == b) {
                    selected[a][j] = true;
                }
            }
        }

        // 注目する辺を選ぶ
        e = {-1, -1};
        for(int i=0;i<n;++i) {
            for(int j=0;j<selected[i].size();++j) {
                if(selected[i][j] == 0) {
                    e.first = i;
                    e.second = graph[i][j];
                    break;
                }
            }
        }

        // いらないノードを消す
        if(e.first != -1) {
            while(history.front() != e.second) {
                history.push_back(history.front());
                history.pop_front();
            }
            while(history.back() != e.first) {
                in_history[history.back()] = false;
                history.pop_back();
            }
        }
    }

    if(!check()) {
        cout << -1 << endl;
    } else {
        show_history();
    }
    return 0;
}


Measured memory_bytes: 384