#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long dis[100005];
long long vis[100005];
bool flag = true;
long long in[100005], out[100005];
vector<vector<long long> > adj;
long long n, m;
vector<long long> ans;
long long visited[100005];
void dfs(long long ver) {
  if (!flag) return;
  vis[ver] = 1;
  for (auto i : adj[ver]) {
    if (vis[i] == 0) {
      dfs(i);
    } else if (vis[i] == 1) {
      flag = false;
      return;
    }
  }
  vis[ver] = 2;
}
void dfs2(long long ver) {
  visited[ver] = 1;
  for (auto i : adj[ver]) {
    if (visited[i] == 0) dfs2(i);
  }
  ans.push_back(ver);
}
void topo() {
  ans.clear();
  fill_n(visited, n + 1, 0);
  for (long long i = 1; i <= n; i++) {
    if (visited[i] == 0) {
      dfs2(i);
    }
  }
  reverse(ans.begin(), ans.end());
}
void cal() {
  for (auto i : ans) {
    for (auto j : adj[i]) {
      if (dis[j] < dis[i] + 1) {
        dis[j] = dis[i] + 1;
      }
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  clock_t clk;
  clk = clock();
  cin >> n >> m;
  long long x, y;
  pair<long long, long long> p[m];
  adj.resize(n + 1);
  for (long long i = 0; i < m; i++) {
    cin >> p[i].first >> p[i].second;
    out[p[i].first]++;
    in[p[i].second]++;
    adj[p[i].first].push_back(p[i].second);
  }
  flag = false;
  for (long long i = 1; i <= n; i++) {
    if (in[i] == 0) {
      flag = true;
      dfs(i);
      break;
    }
  }
  if (!flag) {
    cout << -1;
    return 0;
  }
  long long ans = 1e9;
  long long l = 0, r = m;
  while (l <= r) {
    long long mid = l + (r - l) / 2;
    adj.clear();
    adj.resize(n + 1);
    fill_n(in, n + 1, 0);
    fill_n(out, n + 1, 0);
    fill_n(dis, n + 1, -1e17);
    for (long long i = 0; i < mid; i++) {
      adj[p[i].first].push_back(p[i].second);
      in[p[i].second]++;
      out[p[i].first]++;
    }
    flag = false;
    for (long long i = 1; i <= n; i++) {
      if (in[i] == 0) {
        flag = true;
        dis[i] = 0;
        topo();
        cal();
        break;
      }
    }
    for (long long i = 1; i <= n; i++) {
      if (out[i] == 0) {
        if (dis[i] != n - 1) {
          flag = false;
          break;
        } else {
          flag = true;
          break;
        }
      }
    }
    if (flag) {
      ans = min(ans, mid);
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  if (ans == 1e9) {
    cout << -1;
  } else {
    cout << ans;
  }
  clk = clock() - clk;
  cerr << fixed << setprecision(6) << "Time: " << ((double)clk) / CLOCKS_PER_SEC
       << "\n";
  return 0;
}
