#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 1000, MAX_M = 2000;
int N, M;
int A[MAX_M], B[MAX_M];

vector<int> G[MAX_N];
bool visited[MAX_N];
bool is_inPath[MAX_N];

bool dfs(int s, int v, stack<int>& path) {
  visited[v] = true;
  path.push(v);
  for (int i = 0; i < len(G[v]); ++i) {
    int to = G[v][i];
    if (to == s) {
      return true;
    } else {
      if (!visited[to]) {
        if (dfs(s, to, path)) return true;
      }
    }
  }
  path.pop();
  return false;
}


int main() {

  std::ios::sync_with_stdio(false);std::cin.tie(0);

  cin >> N >> M;
  rep(i, M) cin >> A[i] >> B[i];

  rep(i, M) {
    G[--A[i]].push_back(--B[i]);
  }

  vector<int> circuration;
  for (int i = 0; i < N; ++i) {
    stack<int> path;
    memset(visited, false, sizeof(visited));
    if (dfs(i, i, path)) {
      while (!path.empty()) {
        int p = path.top(); path.pop();
        circuration.push_back(p);
      }
      break;
    }
  }
  reverse(all(circuration));

  if (len(circuration) == 0) {
    cout << -1 << endl;
    return 0;
  }

  bool is_pure;
  do {
    is_pure = true;
    memset(visited, false, sizeof(visited));
    memset(is_inPath, false, sizeof(is_inPath));
    int s = circuration[0];
    int t = circuration[len(circuration)-1];
    for (int i = 0; i < len(circuration); ++i) is_inPath[circuration[i]] = true;
    for (int i = 0; i < len(circuration); ++i) {
      int p = circuration[i];
      visited[p] = true;
      for (int j = 0; j < len(G[p]); ++j) {
        int to = G[p][j];
        if (p != t && to == circuration[i+1]) continue;
        if (p == t && to == s) continue;
        if (is_inPath[to]) {
          is_pure = false;
          vector<int> new_circuration;
          if (visited[to]) {
            int idx = 0;
            while (circuration[idx] != to) ++idx;
            for (int k = idx; k < len(circuration); ++k) {
              new_circuration.push_back(circuration[k]);
              if (k == i) break;
            }
          } else {
            int idx = 0;
            for (idx = 0; idx < len(circuration); ++idx) {
              new_circuration.push_back(circuration[idx]);
              if (idx == i) break;
            }
            while (circuration[idx] != to) ++idx;
            for (int k = idx; k < len(circuration); ++k) {
              new_circuration.push_back(circuration[k]);
            }
          }
          circuration = new_circuration;
          break;
        }
      }
      if (!is_pure) break;
    }
  } while (!is_pure);

  cout << len(circuration) << endl;
  for (int i = 0; i < len(circuration); ++i) {
    cout << (circuration[i]+1) << endl;
  }
  
  return 0;
}


Measured memory_bytes: 384