#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
#define SELECTOR(_1, _2, _3, SELECT, ...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__, _rep1, _rep0)(__VA_ARGS__)
#define _rep0(i, n) for (ll i = 0; i < n; ++i)
#define _rep1(i, k, n) for (ll i = k; i < n; ++i)

void solve(){
  // main coding
  ll n,m; cin>>n>>m;
  ll INF=1<<15;
  vector<vector<ll>> dist(n,vector<ll>(n,INF)); // adjacency matrix
  vector<vector<ll>> E(n); // adjacency list
  rep(_,m) {
    ll a,b; cin>>a>>b;
    --a; --b; // 0-indexed
    dist[a][b]=1;
    E[a].push_back(b);
  }
  // Warshall-Floyd
  rep(k,n) rep(i,n) rep(j,n) {
    dist[i][j]=min(dist[i][k]+dist[k][j],dist[i][j]);
  }
  // loop detection
  ll len=n+1,v;
  rep(i,n) {
    if(dist[i][i]<len) {
      v=i;
      len=dist[i][i];
    }
  }
  if(len==n+1) {
    cout<<-1<<"\n";
    return;
  }
  const ll vm=v;
  vector<ll> ans;
  while(len){
    ans.push_back(v);
    --len;
    rep(i,n) if(dist[v][i]==1 && dist[i][vm]==len){
      v=i;
      break;
    }
  }
  cout<<ans.size()<<"\n";
  for(ll v:ans) cout<<v+1<<"\n";
}

int main(){
  // ios::sync_with_stdio(false);
  // cout<<fixed<<setprecision(10);
  solve();
  return 0;
}
