#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    vector<int> solve(int n, vector<pair<int,int>>& edges) {
        vector<vector<int>> graph(n);
        for (auto& e : edges) {
            int u = e.first, v = e.second;
            graph[u].push_back(v);
        }

        vector<bool> visited(n, false);
        vector<bool> inStack(n, false);
        function<bool(int, vector<int>&)> dfs = [&](int u, vector<int>& path) {
            visited[u] = true;
            inStack[u] = true;

            path.push_back(u);

            for (auto v : graph[u]) {
                if (inStack[v]) {
                    reverse(path.begin(), path.end());
                    while (!path.empty() && path.back() != v) {
                        path.pop_back();
                    }
                    reverse(path.begin(), path.end());
                    return true;
                }    
                if (!visited[v]) {
                    if (dfs(v, path)) {
                        return true;
                    }
                }
            }

            path.pop_back();
            inStack[u] = false;
            return false;
        };

        vector<int> cycle;
        for (int i = 0; i < n; ++i) {
            // cycle.clear();
            // fill(visited.begin(), visited.end(), false);
            // fill(inStack.begin(), inStack.end(), false);
            if (dfs(i, cycle)) {
                break;
            }
        }
        if (cycle.empty()) {
            return {};
        }

        auto check = [&](vector<int>& path) -> pair<int,int> {
            vector<int> pos(n, -1);
            for (int i = 0; i < path.size(); ++i) {
                pos[path[i]] = i;
            }
            for (auto u : path) {
                for (auto v : graph[u]) {
                    if (pos[v] >= 0) {
                        if ((pos[v] - pos[u] + path.size()) % path.size() != 1) {
                            return {u, v};
                        }  
                    }
                }
            }
            return {-1, -1};
        };

        while (true) {
            auto E = check(cycle);
            if (E.first == -1) {
                break;
            }
            int s = E.second;
            int t = E.first;
            int n = cycle.size();

            for (int i = 0; i < n; ++i) {
                if (cycle[i] == s) {
                    int u = cycle[i];
                    vector<int> newCycle;
                    while (true) {
                        newCycle.push_back(u);
                        if (u == t) {
                            break;
                        }
                        u = cycle[(++i) % n];
                    }
                    cycle = newCycle;
                    break;
                }
            }
        }
        
        return cycle;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<pair<int,int>> edges;
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        edges.emplace_back(u, v);
    }
    Solution sol;
    auto res = sol.solve(n, edges);
    if (res.empty()) {
        cout << -1 << "\n";
    } else {
        cout << res.size() << "\n";
        for (auto r : res) {
            cout << r + 1 << "\n";
        }
    }
    return 0;
}

Measured memory_bytes: 384