#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void *wmem;
char memarr[96000000];
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  (*arr)=(T*)(*mem);
  (*mem)=((*arr)+x);
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
struct graph{
  int N;
  int *es;
  int **edge;
  void setDirectEdge(int N__, int M, int A[], int B[], void **mem = &wmem){
    int i;
    N = N__;
    walloc1d(&es, N, mem);
    walloc1d(&edge, N, mem);
    walloc1d(&edge[0], M, mem);
    for(i=(0);i<(N);i++){
      es[i] = 0;
    }
    for(i=(0);i<(M);i++){
      es[A[i]]++;
    }
    for(i=(0);i<(N);i++){
      walloc1d(&edge[i], es[i], mem);
    }
    for(i=(0);i<(N);i++){
      es[i] = 0;
    }
    for(i=(0);i<(M);i++){
      edge[A[i]][es[A[i]]++] = B[i];
    }
  }
  int shortestCycle(int res[] = NULL, void *mem=wmem){
    int i;
    int j;
    int k;
    int r;
    int sz;
    int tp;
    int *q;
    int qs;
    int qe;
    int *arr;
    int *bk;
    if(res==NULL){
      walloc1d(&res, N+1, &mem);
    }
    for(i=(0);i<(N);i++){
      for(j=(0);j<(es[i]);j++){
        k = edge[i][j];
        if(k==i){
          res[0] = res[1] = i;
          return 1;
        }
      }
    }
    walloc1d(&arr, N, &mem);
    walloc1d(&bk, N, &mem);
    walloc1d(&q, N, &mem);
    sz = 1073709056;
    for(r=(0);r<(N);r++){
      for(i=(0);i<(N);i++){
        arr[i] = -1;
      }
      for(i=(0);i<(N);i++){
        bk[i] = -1;
      }
      arr[r] = 0;
      qs = qe = 0;
      q[qe++] = r;
      tp = 1073709056;
      while(qs < qe && tp == 1073709056){
        i = q[qs++];
        for(j=(0);j<(es[i]);j++){
          k = edge[i][j];
          if(k==r){
            bk[k] = i;
            tp = arr[i] + 1;
            break;
          }
          if(arr[k]==-1){
            bk[k] = i;
            arr[k] = arr[i] + 1;
            q[qe++] = k;
            continue;
          }
        }
      }
      if(sz > tp){
        sz = tp;
        res[tp] = r;
        k = r;
        for(;;){
          k = bk[k];
          res[arr[k]] = k;
          if(k==r){
            break;
          }
        }
      }
    }
    if(sz==1073709056){
      sz = -1;
    }
    return sz;
  }
}
;
int N;
int M;
int A[2000];
int B[2000];
int ress;
int res[2000];
int main(){
  wmem = memarr;
  graph g;
  rd(N);
  rd(M);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(M);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);A[Lj4PdHRW] += (-1);
      rd(B[Lj4PdHRW]);B[Lj4PdHRW] += (-1);
    }
  }
  g.setDirectEdge(N, M, A, B);
  ress = g.shortestCycle(res);
  wt_L(ress);
  wt_L('\n');
  if(ress > 0){
    {
      int KL2GvlyY;
      for(KL2GvlyY=(0);KL2GvlyY<(ress);KL2GvlyY++){
        wt_L(res[KL2GvlyY]+1);
        wt_L('\n');
      }
    }
  }
  return 0;
}
// cLay varsion 20190929-1 [beta]

// --- original code ---
// int N, M, A[2000], B[2000];
// int ress, res[2000];
// {
//   graph g;
//   rd(N,M,(A--,B--)(M));
//   g.setDirectEdge(N, M, A, B);
//   ress = g.shortestCycle(res);
//   wt(ress);
//   if(ress > 0) wtLn(res(ress)+1);
// }


Measured memory_bytes: 256