/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class FPure {
public:

    vector<int> graph[1001];
    vector<bool> used;
    vector<int> ret;
    vector<int> cost;
    int n;

    bool dijkstra(int p) {
      vector<int> cost(n+1, INT_MAX/2);
      vector<int> parent(n+1);
      deque<P> que;
      cost[p] = 0;
      que.emplace_back(p, 0);
      while(!que.empty()) {
        P pa = que.front(); que.pop_front();
        int s = pa.first;
        int c = pa.second;
        if (c > cost[s]) continue;
        for(auto e: graph[s]) {
          if (e == p) {
            ret.push_back(e);
            e = s;
            while(e != p) {
              ret.push_back(e);
              e = parent[e];
            }
            reverse(all(ret));
            return true;
          }
          if (cost[e] > c + 1) {
            cost[e] = c+1;
            parent[e] = s;
            que.emplace_back(e, c+1);
          }
        }
      }
      return false;
    }

    void solve(istream& cin, ostream& cout) {
      SPEED;
      int m; cin >> n >> m;
      used.resize(n+1);
      cost.resize(n+1);
      rep(i, m) {
        int a, b; cin >> a >> b;
        graph[a].push_back(b);
      }

      for(int i=1; i<=n; i++) {
        if (dijkstra(i)) break;
      }

      if (ret.empty()) {
        cout << -1 << endl;
        return;
      }

      for(auto e: ret) {
        debug(e);
      }

      vector<int> vec = ret;
      vector<int> vec2;
      vector<bool> check(vec.size());
      vector<int> candidate(n+1);
      for(auto e: vec) {
        candidate[e] = true;
      }
      bool flag = true;
      while(flag) {
        flag = false;
        int p = -1;
        int q = -1;
        int s = vec.size();
        rep(i, s) {
          for(auto e: graph[vec[i]]) {
            if (e != vec[(i+1)%s] && candidate[e]) {
              p = i;
              q = e;
              flag = true;
              break;
            }
          }
          if (flag) break;
        }
        if (flag) {
          p++;
          rep(i, s) check[i] = false;
          while(vec[p%s] != q) {
            check[p%s] = true;
            p++;
          }
          rep(i, s) {
            if (!check[i]) {
              vec2.push_back(vec[i]);
            } else {
              candidate[vec[i]] = false;
            }
          }
          swap(vec, vec2);
          vec2.clear();
        }
      }

      cout << vec.size() << endl;
      for(auto e: vec) {
        cout << e << '\n';
      }

    }
};

signed main() {
  FPure solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 384