#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++)
#define rep(i, begin, end) for(int i = int(begin); i < int(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
#define lint long long
auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;};
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail){
  std::cerr << " " << head;
  debug_impl(tail...);
}
#ifndef STOPIT
#define debug(...)\
  std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
  debug_impl(__VA_ARGS__);\
  std::cerr << std::noboolalpha;
#else
#define debug 0;
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

template <typename T>
auto make_vector_impl(size_t sz, T t) {return std::vector<T>(sz, t);}

template <size_t N, typename T, typename U, std::enable_if_t<N == 1, std::nullptr_t> = nullptr>
auto make_vector(size_t sz, U u) {return make_vector_impl(sz, T(u));}

template <size_t N, typename T, std::enable_if_t<N == 1, std::nullptr_t> = nullptr>
auto make_vector(size_t sz) {return std::vector<T>(sz);}

template <size_t N, typename T, typename... Args, std::enable_if_t<N != 1, std::nullptr_t> = nullptr>
auto make_vector(size_t a, Args... args) {return make_vector_impl(a, make_vector<N - 1, T>(args...));}

template <typename T, typename Size_t>
auto& at(T& t, Size_t i) {return t.at(i);}

template <typename T, typename Size_t, typename... Args>
auto& at(T& t, Size_t i, Args... args) {return at(t.at(i), args...);}

void err () {
  std::cout << -1 << std::endl;
  exit(0);
}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  constexpr int inf = 1 << 30;
  int n, m; std::cin >> n >> m;
  auto graph = make_vector< 2, int >(n, 0);
  auto rev   = make_vector< 2, int >(n, 0);
  loop(m) {
    int u, v; std::cin >> u >> v;
    u--, v--;
    graph.at(u).emplace_back(v);
    rev  .at(v).emplace_back(u);
  }
  auto bfs = [&] (auto start) {
    auto dist = std::vector< int > (n, inf);
    std::queue< int > que;
    que.emplace(start);
    while (!que.empty()) {
      auto crr = que.front(); que.pop();
      for (auto nxt : graph.at(crr)) {
        if (dist.at(nxt) != inf) continue;
        que.emplace(nxt);
        dist.at(nxt) = (crr == start ? 0 : dist.at(crr)) + 1;
      }
    }
    auto len = dist.at(start);
    if (len == inf)
      { return std::vector< int > {}; }

    std::vector< int > ret(len);
    ret.at(len - 1) = start;
    auto crr = start;
    for (auto d = len - 1; d >= 1; d--) {
      auto found = -1;
      for (auto nxt : rev.at(crr)) {
        if (dist.at(nxt) == d) {
          found = nxt;
          break;
        }
      }
      assert(found != -1);
      crr = found;
      ret.at(d - 1) = found;
    }
    return ret;
  };
  auto min = inf;
  std::vector< int > ret;
  rep(i, 0, n) {
    auto now = bfs(i);
    auto len = (int)now.size();
    // debug(now);
    if (len != 0 && cmn(min, len)) {
      std::swap(ret, now);
    }
  }
  if (ret.empty()) err();
  std::cout << ret.size() << std::endl;
  for (auto x : ret) std::cout << x + 1 << std::endl;
  return 0;
}


Measured memory_bytes: 384