#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
vector<pair<int, int> > g[N];
vector<pair<int, int> > r[N];
int n, m;
int deg[N];
bool vis[N];
bool check(int t) {
  for (int i = 0; i < n; i++) deg[i] = 0;
  for (int i = 0; i < n; i++) {
    for (auto j : g[i])
      if (j.second <= t) deg[j.first]++;
  }
  queue<int> q;
  for (int i = 0; i < n; i++) {
    if (deg[i] == 0) q.push(i);
  }
  while (q.size()) {
    if (q.size() > 1) return false;
    int ind = q.back();
    q.pop();
    for (auto j : g[ind])
      if (j.second <= t) {
        deg[j.first]--;
        if (deg[j.first] == 0) q.push(j.first);
      }
  }
  return true;
}
void dfs2(int v, int t) {
  vis[v] = true;
  for (auto i : r[v])
    if (i.second <= t && !vis[i.first]) dfs2(i.first, t);
}
void dfs1(int v, int t) {
  vis[v] = true;
  for (auto i : g[v])
    if (i.second <= t && !vis[i.first]) dfs1(i.first, t);
}
bool check2(int t) {
  fill(vis, vis + n, false);
  dfs1(0, t);
  dfs2(0, t);
  for (int i = 0; i < n; i++)
    if (!vis[i]) return false;
  return true;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(pair<int, int>(b, i));
    r[b].push_back(pair<int, int>(a, i));
  }
  int l = -1, r = m;
  while (r - l > 1) {
    int mid = (r + l) / 2;
    if (check2(mid))
      r = mid;
    else
      l = mid;
  }
  if (r == m) {
    cout << -1 << endl;
    return 0;
  }
  l = r - 1;
  r = m;
  while (r - l > 1) {
    int mid = (r + l) / 2;
    if (check(mid))
      r = mid;
    else
      l = mid;
  }
  if (r == m) {
    cout << -1 << endl;
    return 0;
  }
  cout << r + 1 << endl;
}
