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

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> edges[1000];
    for(int i=0; i<M; i++){
        int a, b;
        cin >> a >> b;
        edges[a-1].push_back(b-1);
    }

    vector<int> ans;
    for(int s=0; s<N; s++){
        bitset<1000> visited;
        vector<int> prv(N);
        queue<int> que;
        que.push(s);
        visited[s] = 1;
        while(que.size()){
            int i = que.front(); que.pop();
            for(int j : edges[i]){
                if(j == s){
                    vector<int> res = {i};
                    while(i != s){
                        i = prv[i];
                        res.push_back(i);
                    }
                    reverse(res.begin(), res.end());
                    if(ans.size() == 0 || ans.size() > res.size()){
                        ans = res;
                    }
                    while(que.size()) que.pop();
                    break;
                }
                if(visited[j]) continue;
                visited[j] = 1;
                prv[j] = i;
                que.push(j);
            }
        }
    }
    if(ans.size()){
        cout << ans.size() << endl;
        for(int a : ans) cout << a+1 << endl;
    }else{
        cout << -1 << endl;
    }
}
