#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007
#define MAX 2100000

int main(){
  int N,M;
  cin>>N>>M;
  vector<int> A(M),B(M);
  vector<vector<int>> G(N),H(N);
  for(int i=0;i<M;i++){
    cin>>A.at(i)>>B.at(i);
    A.at(i)--,B.at(i)--;
    G.at(A.at(i)).push_back(B.at(i));
    H.at(B.at(i)).push_back(A.at(i));
  }

  vector<int> Ans(10000);
  for(int i=0;i<N;i++){
    vector<int> dist(N,100000);
    dist.at(i)=0;
    queue<int> q;
    q.push(i);
    int y=-1;
    while(!q.empty()){
      int v=q.front();
      for(auto nv:G.at(v)){
        if(nv==i){
          y=v;
          break;
        }
        if(dist.at(nv)==100000){
          dist.at(nv)=dist.at(v)+1;
          q.push(nv);
        }
      }
      q.pop();
    }
    if(y==-1){
      continue;
    }
    vector<int> ans;
    ans.push_back(y);
    while(y!=i){
      for(auto ny:H.at(y)){
        if(dist.at(y)==dist.at(ny)+1){
          y=ny;
          break;
        }
      }
      ans.push_back(y);
    }
    if(ans.size()<Ans.size()){
      Ans=ans;
    }
  }

  if(Ans.size()==10000){
    cout<<-1<<endl;
  }else{
    cout<<Ans.size()<<endl;
    for(int i=0;i<Ans.size();i++){
      cout<<Ans.at(i)+1<<endl;
    }
  }
}
