#include <iostream>
#include<bits/stdc++.h>
using namespace std;
vector<int>v[1000],tmp,ans;
int n,m,a,b,c,pre[1000],dist[1000],MIN,cur;
int main(void){
    cin>>n>>m;
    MIN=n+1;
    for(int i=0;i<m;i++){
        cin>>a>>b;
        a--,b--;
        v[a].push_back(b);
    }
    for(int i=0;i<n;i++){
        queue<int> que;
        for(int i=0;i<n;i++)pre[i]=-1;
        for(int i=0;i<n;i++)dist[i]=-1;
        que.push(i);
        dist[i]=1;
        while(que.size()){
            int q=que.front();
            que.pop();
            for(int x:v[q]){
                if(dist[x]==-1){
                    dist[x]=dist[q]+1;
                    pre[x]=q;
                    que.push(x);
                }
                else if(x==i){
                    while(!que.empty())que.pop();
                    tmp={i};
                    int cur=q;
                    while(cur!=i){tmp.push_back(cur),cur=pre[cur];}
                    if(MIN>tmp.size())MIN=tmp.size(),ans=tmp;
                }
            }
        }
    }
    if(MIN==n+1)cout<<-1<<endl;
    else{
        cout<<MIN<<endl;
        for(int x:ans){
            cout<<x+1<<endl;
        }
    }
}
