#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>>;

/// Find the shortest cycle that include the node `s`.
///
/// 1. Compute the distance from the node `s` by BFS.
/// 2. Check whether a cycle can be constituted, by iterating each edge.
///
/// The time complexity is O(n + m).
std::vector<int> shortest_cycle_on(const Graph &g, const int s) {
  const int n = g.size();

  // 1. Compute the distance from the node `s` by BFS.
  std::vector<int> dist(n, -1);
  std::vector<int> prev(n, -1);
  std::queue<int> pool;
  dist[s] = 0;
  pool.push(s);
  while (not pool.empty()) {
    const int v = pool.front();
    pool.pop();
    for (auto w : g[v]) {
      if (dist[w] >= 0)
        continue;
      dist[w] = dist[v] + 1;
      prev[w] = v;
      pool.push(w);
    }
  }

  int res_size = n + 1;
  std::vector<int> res;

  // 2. Check whether a cycle can be constituted, by iterating each edge.
  for (int u = 0; u < n; ++u) {
    // If it is not a arrival node, then skip
    if (u == s or dist[u] == -1)
      continue;

    for (auto v : g[u]) {
      // If the endpoint is other than the node s, then skip
      if (v != s)
        continue;

      // Restore the cycle
      std::vector<int> cycle;
      int w = u;
      while (w != -1) {
        cycle.push_back(w);
        w = prev[w];
      }
      std::reverse(cycle.begin(), cycle.end());

      // Update
      if ((int)cycle.size() < res_size) {
        res_size = cycle.size();
        res = cycle;
      }
    }
  }

  return res;
}

/// Find the shortest cycle.
///
/// For each node, compute the shortest cycle including that node.
///
/// The time complexity is O(n(n + m)).
std::vector<int> shortest_cycle(const Graph &g) {
  const int n = g.size();
  int res_size = n + 1;
  std::vector<int> res;
  for (int s = 0; s < n; ++s) {
    auto cycle = shortest_cycle_on(g, s);
    if (cycle.empty())
      continue;
    if ((int)cycle.size() < res_size) {
      res_size = (int)cycle.size();
      res = cycle;
    }
  }
  return res;
}


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

  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 res = shortest_cycle(g);

  if ((int)res.size() == 0)
    std::cout << -1 << std::endl;
  else {
    std::cout << res.size() << std::endl;
    for (auto v: res)
      std::cout << v + 1 << std::endl;
  }

  return 0;
}


Measured memory_bytes: 384