#include <bits/stdc++.h>
using namespace std;
int indeg[100010 + 1], lf[100010 + 1], rt[100010 + 1], dist[100010 + 1];
vector<int> v[100010 + 1], topo;
void dfs(int x, int p) {
  dist[x] = p;
  topo.push_back(x);
  for (int i = 0; i < v[x].size(); i++) {
    indeg[v[x][i]]--;
    if (!indeg[v[x][i]]) dfs(v[x][i], p + 1);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m, l, r, mid, maxi;
  cin >> n >> m;
  if (n == 2) {
    cout << 1 << "\n";
    return 0;
  }
  if (m < n) {
    cout << -1 << "\n";
    return 0;
  }
  for (int i = 0; i < m; i++) {
    cin >> lf[i] >> rt[i];
    v[lf[i]].push_back(rt[i]);
    indeg[rt[i]]++;
  }
  for (int i = 1; i <= n; i++)
    if (!indeg[i]) dfs(i, 1);
  for (int i = 0; i < topo.size(); i++)
    for (int j = 0; j < v[topo[i]].size(); j++)
      if (dist[v[topo[i]][j]] < (dist[topo[i]] + 1))
        dist[v[topo[i]][j]] = 1 + dist[topo[i]];
  maxi = 0;
  topo.clear();
  for (int i = 1; i <= n; i++) {
    maxi = max(maxi, dist[i]);
    v[i].clear();
    indeg[i] = 0;
    dist[i] = 0;
  }
  if (maxi != n) {
    cout << -1 << "\n";
    return 0;
  }
  l = n - 1;
  r = m;
  mid = l + ((r - l) / 2);
  while (l < r) {
    for (int i = 0; i < mid; i++) {
      v[lf[i]].push_back(rt[i]);
      indeg[rt[i]]++;
    }
    for (int i = 1; i <= n; i++)
      if (!indeg[i]) dfs(i, 1);
    for (int i = 0; i < topo.size(); i++)
      for (int j = 0; j < v[topo[i]].size(); j++)
        if (dist[v[topo[i]][j]] < (dist[topo[i]] + 1))
          dist[v[topo[i]][j]] = 1 + dist[topo[i]];
    maxi = 0;
    for (int i = 1; i <= n; i++) {
      maxi = max(maxi, dist[i]);
      dist[i] = 0;
      v[i].clear();
      indeg[i] = 0;
    }
    topo.clear();
    if (maxi == n)
      r = mid;
    else
      l = mid + 1;
    mid = l + ((r - l) / 2);
  }
  cout << mid << "\n";
  return 0;
}
