//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>
#include <locale>
#include <random>
#include <type_traits>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

using LL = long long;

//------------------------------------------
//------------------------------------------

template<class T>
struct Edge {
    int from, to;
    T cost;

    Edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}

    explicit operator int() const { return to; }
};

template<class T>
using Edges = vector<Edge<T>>;

template<class T>
using WeightedGraph = vector<Edges<T>>;

using UnWeightedGraph = vector<vector<int>>;

template<class T>
using DistMatrix = vector<vector<T>>;

template<class G>
class CycleFind {
private:
    int V;
    int key_v;
    vector<bool> going;
    vector<bool> backing;
    vector<int> cycle_path;
    stack<int> history;
    const G &graph;

public:

    CycleFind(const G &_graph) : graph(_graph), key_v(-1) {
        V = graph.size();
        going = vector<bool>(V, false);
        backing = vector<bool>(V, false);
        build();
    }

    void dfs(int v, int p) {
        going[v] = true;
        history.push(v);
        for (auto e: graph[v]) {
            int to = (int) e;
            if (to == p) continue;
            if (backing[to])continue;
            if (going[to] && !backing[to]) {
                key_v = to;
                return;
            }
            dfs(to, v);
            if (key_v != -1) return;
        }
        history.pop();
        backing[v] = true;
    }

    bool has_cycle() {
        return key_v != -1;
    }

    vector<int> get_cycle_path() const {
        return cycle_path;
    }

    void build() {
        for (int i = 0; i < V; i++) if (!going[i] && key_v == -1) dfs(i, -1);
        if (has_cycle()) {
            cycle_path = vector<int>();
            while (!history.empty()) {
                auto v = history.top();
                history.pop();
                cycle_path.push_back(v);
                if (v == key_v) break;
            }
        }
    }

};

template<typename T>
class Dijkstra {
    using Pr = pair<T, int>;
private:
    int V;
    const WeightedGraph<T> &graph;
    const T INF = numeric_limits<T>::max();
    vector<T> dist;
    vector<int> prev;

public:

    Dijkstra(const WeightedGraph<T> &graph, int s) : graph(graph) {
        V = graph.size();
        dijkstra(s);
    }

    void dijkstra(int s) {
        priority_queue<Pr, vector<Pr>, greater<>> Q;
        dist = vector<T>(V, INF);
        prev = vector<int>(V, -1);
        Q.push(make_pair(0, s));
        dist[s] = 0;
        while (!Q.empty()) {
            auto p = Q.top();
            Q.pop();
            T now = p.first;
            int v = p.second;
            if (dist[v] < now)continue;
            for (auto e: graph[v]) {
                int to = e.to;
                T cost = e.cost;
                if (dist[to] > dist[v] + cost) {
                    dist[to] = dist[v] + cost;
                    prev[to] = v;
                    Q.push(make_pair(dist[to], to));
                }
            }
        }
    }

    vector<T> get_dist() const {
        return dist;
    }

    vector<int> get_prev() const {
        return prev;
    }

};

int main() {

    int N, M;
    cin >> N >> M;

    WeightedGraph<int> G(N);

    set<pair<int, int>> st;

    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        st.insert(make_pair(a, b));
        G[a].push_back({a, b, 1});
    }

    CycleFind<WeightedGraph<int>> cycleFind(G);
    if (!cycleFind.has_cycle()) {
        cout << -1 << endl;
        return 0;
    }

    int len = 1e6;
    vector<int> ans;
    for (int i = 0; i < N; i++) {
        Dijkstra<int> dijkstra(G, i);
        vector<int> dist = dijkstra.get_dist();
        vector<int> prev = dijkstra.get_prev();
        for (int j = 0; j < N; j++) {
            if (i == j)continue;
            if (st.count(make_pair(j, i))) {
                if (len > dist[j]) {
                    len = dist[j];
                    ans = vector<int>();
                    int v = j;
                    while (v != -1) {
                        ans.push_back(v);
                        v = prev[v];
                    }
                }
            }
        }
    }

    cout << ans.size() << endl;
    reverse(ans.begin(), ans.end());
    for(int i = 0;i<ans.size();i++)cout << ans[i] + 1  << endl;

    return 0;
}
































Measured memory_bytes: 512