#include <bits/stdc++.h>
 
const double pi = 3.141592653589793238462643383279;
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
 
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const double EPS = 1E-10;
 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)


//ここから編集
int N, M;

vector<vector<int>> g(2010);
int depth[1010];
map<int, int> mp;
pii path;
bool ok = false;
bool visited[1010];
void dfs(int v, int par, int s, int d){
  //cout << s << " " <<  v << endl;
  if(depth[v] != -1){
    if(v == s){
      //閉路
      path = make_pair(par, v);
      ok = true;
    
    }
    return;
  }

  depth[v] = d;

  for(auto u: g[v]){
    dfs(u, v, s, d+1);
  }
}

void dfs2(int v, int par, int t, map<int, int>& mp){

  if(v == t){
    mp[t] = par;
    ok = true;
    return;
  }
  visited[v] = true;
  for(auto u: g[v]){
    if(!visited[u]) dfs2(u, v, t, mp);
    if(ok) break;
  }
  mp[v] = par;
  
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  
  cin >> N >> M;
  REP(i,M){
    int a, b; cin >> a >> b;
    a--; b--;
    g[a].push_back(b);
  }

  int vv=-1, uu=-1;
  REP(i,N){

    for(auto v: g[i]){

      for(auto u: g[v]){
        if(vv ==-1 && u == i){
          vv = v,  uu = i;
          break;
        }
      }
    }
  }
  if(vv != -1 && uu !=-1){
    cout << 2 << endl;
    cout << vv+1 << "\n" << uu+1 <<"\n";
    return 0;
  }
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++) depth[j] = -1;
    dfs(i, -1, i, 0);

    if(ok) break;
  }

  //cout << path.first << " " << path.second << endl;

  if(ok){
    int s = path.second;
    int t = path.first;

    map<int, int> mp;
    ok = false;
    memset(visited, false, sizeof(visited));
    dfs2(s, -1, t, mp);

    vector<int> memo(N, -1);
    int pos = t;
    vector<int> h;
    while(pos != -1){
      h.push_back(pos);
      pos = mp[pos];
    }
    reverse(all(h));
    for(int i=0; i<h.size(); i++)memo[h[i]] = i;
    // for(int i=0; i<h.size(); i++){
    //   cout << h[i] << " ";
    // }
    
    // cout << endl;
    bool update = true;
    while(update){
      update = false;
      s = -1, t = -1;
      for(int i=0; i<h.size(); i++){
        for(auto v: g[h[i]]){
          if(memo[v] != -1 && (memo[v] != (i+1)%h.size() && (memo[v]+1)%h.size() != i)){
            s = i;
            t = memo[v];
            update = true;
            break;
          }
        }
        if(s != -1) break;
      }
      if(s == -1 && t == -1) break;
      //cout << s << " " << t << endl;
      vector<int> new_h;
      for(int i=0; i<N; i++) memo[i] = -1;

      if(s < t){
        for(int i=0; i<=s; i++){
          new_h.push_back(h[i]);
          memo[h[i]] = new_h.size()-1;
        }

        for(int i=t; i<h.size(); i++){
          new_h.push_back(h[i]);
          memo[h[i]] = new_h.size()-1;
        }
      }else{
        for(int i=t; i<=s; i++){
          new_h.push_back(h[i]);
          memo[h[i]] = new_h.size()-1;
        }
      }

      h = new_h;
    }

    cout << h.size() << endl;
    for(auto e: h) cout << e+1 << endl;
  }else{
    cout << -1 << endl;
  }
  return 0;
}


Measured memory_bytes: 3860