#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

template <class T> inline bool chmin(T &a, const T &b) {
  return (a > b) ? a = b, true : false;
}

template <class T> inline bool chmax(T &a, const T &b) {
  return (a < b) ? a = b, true : false;
}

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
  if (v.empty())
    return s;
  s << *v.begin();
  for (auto iter = v.begin() + 1; iter != v.end(); ++iter)
    if (std::is_fundamental<T>::value)
      s << " " << *iter;
    else
      s << std::endl << *iter;
  return s;
}

using Graph = std::vector<std::vector<int>>;
std::vector<bool> visited;  // visited.assign(n, false);
std::vector<bool> finished; // finished.assign(n, false);
std::stack<int> history;

int dfs(const Graph &g, const int v) {
  visited[v] = true;
  history.push(v);
  for (auto w : g[v]) {
    if (finished[w])
      continue;

    if (visited[w])
      return w;

    const int res = dfs(g, w);
    if (res != -1)
      return res;
  }
  history.pop();
  finished[v] = true;
  return -1;
}

std::vector<int> detect_cycle(const Graph &g) {
  for (int s = 0; s < (int)g.size(); ++s) {
    if (visited[s])
      continue;

    const int res = dfs(g, s);
    if (res != -1) {
      // Restore the cycle
      std::vector<int> cycle;
      while (not history.empty()) {
        int v = history.top();
        history.pop();
        cycle.push_back(v);
        if (v == res)
          break;
      }
      std::reverse(cycle.begin(), cycle.end());
      return cycle;
    }
  }
  return std::vector<int>();
}

int main() {
  int n, m;
  std::cin >> n >> m;

  visited.assign(n, false);
  finished.assign(n, false);

  Graph g(n);
  for (int i = 0; i < m; ++i) {
    int a, b;
    std::cin >> a >> b;
    g[a - 1].push_back(b - 1);
  }

  auto cycle = detect_cycle(g);
  if (cycle.size() == 0) {
    std::cout << -1 << std::endl;
    return 0;
  }


  // サイクルの中に近道があるたびに小さくしていく
  while (true) {

    std::vector<int> order(n, -1);
    for (int i = 0; i < (int)cycle.size(); ++i)
      order[cycle[i]] = i;

    // 近道の探索
    int from = -1;
    int to = -1;
    for (int i = 0; i < (int)cycle.size(); ++i) {
      for (auto nv : g[cycle[i]]) {
        if (nv != cycle[(i + 1) % cycle.size()] and order[nv] != -1) {
          from = i;
          to = order[nv];
        }
      }
    }

    // 近道がない場合は終了
    if (from == -1)
      break;

    // 近道を用いたサイクルの復元
    std::vector<int> new_cycle;
    new_cycle.push_back(cycle[from]);
    int index = to;
    while (index != from) {
      new_cycle.push_back(cycle[index]);
      index = (index + 1) % cycle.size();
    }

    cycle = new_cycle;
  }

  std::cout << cycle.size() << std::endl;
  for (auto v : cycle)
    std::cout << v + 1 << std::endl;

  return 0;
}


Measured memory_bytes: 384