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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N, M;
  cin >> N >> M;
  vll IN(N,0), OUT(N,0);
  vvll Graph(N), InvGraph(N);
  REP(i,M){
    ll A, B;
    cin >> A >> B;
    A--; B--;
    Graph[A].pb(B);
    InvGraph[B].pb(A);
    OUT[A]++; IN[B]++;
  }

  REP(i,N){
    stack<ll> que;
    que.push(i);
    while(que.size()){
      ll pos = que.top(); que.pop();
      if(IN[pos]!=0) continue;
      REP(j,Graph[pos].size()){
        ll next_pos = Graph[pos][j];
        OUT[pos]--;
        IN[next_pos]--;
        que.push(next_pos);
      }
    }
  }

  REP(i,N){
    stack<ll> que;
    que.push(i);
    while(que.size()){
      ll pos = que.top(); que.pop();
      if(OUT[pos]!=0) continue;
      REP(j,InvGraph[pos].size()){
        ll next_pos = InvGraph[pos][j];
        IN[pos]--;
        OUT[next_pos]--;
        que.push(next_pos);
      }
    }
  }

  set<ll> st;
  REP(i,N){
    if(IN[i]<=0) continue;
    if(OUT[i]<=0) continue;
    st.emplace(i);
  }

  vll ans;
  ll final_val = -1;

  REP(i,N){
    if(st.find(i)==st.end()) continue;
    set<ll> st2;
    queue<ll> que;
    que.push(i);
    while(que.size()){
      ll pos = que.front(); que.pop();
      if(st2.find(pos)!=st2.end()){
        final_val = pos;
        break;
      }
      ans.push_back(pos);
      st2.emplace(pos);

      set<ll> st3;
      queue<ll> que2;
      ll next_pos = -1;
      REP(i,InvGraph[pos].size()){
        ll tmp = InvGraph[pos][i];
        if(st.find(tmp)==st.end()) continue;
        que2.push(tmp);
        st3.emplace(tmp);
      }
      while(que2.size()){
        ll tmp = que2.front(); que2.pop();
        REP(i,InvGraph[tmp].size()){
          ll tmptmp = InvGraph[tmp][i];
          if(tmptmp==pos){
            next_pos = tmp;
            goto HOGE;
          }
          if(st.find(tmptmp)==st.end()) continue;
          if(st3.find(tmptmp)!=st3.end()) continue;
          que2.push(tmptmp);
          st3.emplace(tmptmp);
        }
      }
HOGE:
      que.push(next_pos);
    }
    break;
  }

  //debug_print(final_val);
  if(final_val<0){
    printf("-1\n");
    return 0;
  }

  ll target_index = 0;
  REP(i,ans.size()){
    if(ans[i]==final_val){
      target_index = i;
      break;
    }
  }

  if(ans.size()-target_index<=0){
    printf("-1\n");
    return 0;
  }
  printf("%lld\n", ans.size()-target_index);
  FOR(i,target_index,ans.size()){
    printf("%lld\n", ans[i]+1);
  }




  return 0;
}

Measured memory_bytes: 512