#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;

const int N = 1010;

int n,m;
vector<int> adj[N];
int vis[N];

vector<int> ans;

void dfs(int u, int ra, vector<int>& sta) {
  if (vis[u]) {
    if (u == ra && (ans.empty() || ans.size() > sta.size())) {
      ans = sta;
    }
    return;
  }
  vis[u] = 1;
  sta.push_back(u);

  for (auto& v : adj[u]) {
    dfs(v, ra, sta);
  }

  sta.pop_back();
}

void check(int u) {
  memset(vis, 0, sizeof vis);
  vector<int> sta;
  dfs(u, u, sta);
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  for (int i=1; i<=m; ++i) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
  }

  for (int i=1; i<=n; ++i) {
    check(i);
  }

  if (ans.size() == 0) {
    cout << -1 << endl;
    return 0;
  }

  cout << ans.size() << endl;
  for (auto& x : ans) {
    cout << x << "\n";
  }
  return 0; 
}
