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

// https://atcoder.jp/contests/abc142/submissions/8554606 を参考
// 最小閉路を探せばよいので全ての頂点からdfs

vector<int> graph[1001];
vector<int> ans, cur;
bitset<1001>flag;
void dfs(int v){
    if(flag[v]) return;
    flag[v] = 1;
    cur.push_back(v);
    for (int x: graph[v]) {
        if(cur[0] == x){
            if(ans.size() == 0 || ans.size() > cur.size()) ans = cur;
        } else {
            dfs(x);
        }
    }
    cur.pop_back();
}

int main() {
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < M; ++i) {
        int A, B;
        cin >> A >> B;
        graph[A].push_back(B);
    }

    for (int i = 1; i <= N; ++i) {
        flag.reset();
        dfs(i);
    }

    if(ans.size() == 0) {
        cout << -1 << "\n";
        return 0;
    }
    cout << ans.size() << "\n";
    for (int x: ans) {
        cout << x << "\n";
    }
    return 0;
}