#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <functional>

constexpr intmax_t  operator ""_jd(unsigned long long n) { return n; }
constexpr uintmax_t operator ""_ju(unsigned long long n) { return n; }
constexpr size_t    operator ""_zu(unsigned long long n) { return n; }
// constexpr ptrdiff_t operator ""_td(unsigned long long n) { return n; }

template <typename WeightType>
class weighted_edge {
public:
  using size_type = size_t;
  using weight_type = WeightType;

protected:
  size_type M_src, M_dst;
  weight_type M_weight;

public:
  weighted_edge() = default;
  weighted_edge(weighted_edge const&) = default;
  weighted_edge(weighted_edge&&) = default;

  weighted_edge(size_type s, size_type d, weight_type w):
    M_src(s), M_dst(d), M_weight(w)
  {}

  weighted_edge& operator =(weighted_edge const&) = default;
  weighted_edge& operator =(weighted_edge&&) = default;

  bool operator <(weighted_edge const& other) const {
    if (M_weight < other.M_weight) return true;
    if (other.M_weight < M_weight) return false;
    if (M_src != other.M_src) return M_src < other.M_src;
    return M_dst < other.M_dst;
  }

  size_type source() const { return M_src; }
  size_type target() const { return M_dst; }
  weight_type weight() const { return M_weight; }
};

struct directed_tag {};
struct undirected_tag {};

template <typename Edge, typename Directedness>
class adjacency_list {
public:
  using size_type = size_t;
  using edge_type = Edge;
  using weight_type = typename Edge::weight_type;
  static constexpr weight_type inf = std::numeric_limits<weight_type>::max();

private:
  std::vector<std::vector<edge_type>> M_g;

public:
  adjacency_list() = default;
  adjacency_list(adjacency_list const&) = default;
  adjacency_list(adjacency_list&&) = default;
  adjacency_list(size_type n): M_g(n) {}

  template <typename... Args>
  void emplace(size_type src, size_type dst, Args... args) {
    M_g[src].emplace_back(src, dst, args...);
    if (std::is_same<Directedness, undirected_tag>::value)
      M_g[dst].emplace_back(dst, src, args...);
  }

  size_type size() const { return M_g.size(); }
  std::vector<edge_type> const& operator [](size_type i) const { return M_g[i]; }
};

template <typename Edge, typename Directedness>
constexpr typename Edge::weight_type inf = adjacency_list<Edge, Directedness>::inf;

template <typename Edge>
std::vector<size_t> min_cycle(adjacency_list<Edge, directed_tag> const& g,
                              size_t s) {

  using weight_type = typename Edge::weight_type;
  using pair_type = std::pair<weight_type, size_t>;
  size_t n = g.size();
  std::vector<weight_type> dp(n, std::numeric_limits<weight_type>::max());
  std::vector<size_t> prev(n, -1);
  dp[s] = weight_type(0);
  std::priority_queue<pair_type, std::vector<pair_type>, std::greater<>> pq;
  pq.emplace(weight_type(0), s);
  while (!pq.empty()) {
    weight_type w;
    size_t v;
    std::tie(w, v) = pq.top();
    pq.pop();
    if (dp[v] < w) continue;
    for (auto const& e: g[v]) {
      weight_type nw = dp[e.source()] + e.weight();
      size_t nv = e.target();
      if (nw < dp[nv]) {
        dp[nv] = nw;
        prev[nv] = v;
        pq.emplace(std::move(nw), nv);
      }
    }
  }

  weight_type res_cw = g.inf;
  std::vector<size_t> res;
  for (size_t i = 0; i < n; ++i) {
    if (i == s) continue;
    weight_type cur_cw = dp[i];
    if (cur_cw == g.inf) continue;
    size_t last = -1;
    for (auto const& e: g[i])
      if (e.target() == s) {
        last = e.source();
        cur_cw += e.weight();
        break;
      }

    if (last == -1_zu) continue;
    if (res_cw < cur_cw) continue;
    res_cw = cur_cw;
    res.clear();
    for (size_t v = last; v != s; v = prev[v]) res.push_back(v);
    res.push_back(s);
    std::reverse(res.begin(), res.end());
  }
  return res;
}

int main() {
  size_t n, m;
  scanf("%zu %zu", &n, &m);

  adjacency_list<weighted_edge<int>, directed_tag> g(n);
  for (size_t i = 0; i < m; ++i) {
    size_t a, b;
    scanf("%zu %zu", &a, &b);
    --a, --b;
    g.emplace(a, b, 1);
  }

  std::vector<size_t> res;
  for (size_t i = 0; i < n; ++i) {
    auto cy = min_cycle(g, i);
    if (cy.empty()) continue;
    if (res.empty() || res.size() > cy.size())
      res = std::move(cy);
  }

  if (res.empty()) return puts("-1"), 0;

  printf("%zu\n", res.size());
  for (auto ri: res) printf("%zu\n", ri+1);
}


Measured memory_bytes: 384