#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 2;
vector<pair<int, int>> grafo[maxN];
int grado[maxN];
bool visitados[maxN];
vector<int> topoSort;
stack<int> Stack;
void topoSortIt(int k, int u) {
  visitados[u] = true;
  for (auto w : grafo[u]) {
    if (visitados[w.first] == false && w.second <= k) {
      topoSortIt(k, w.first);
    }
  }
  Stack.push(u);
  return;
}
void topoSorting(int k, int v, int n) {
  for (int i = 0; i < int(n); i++) visitados[i] = false;
  topoSort.empty();
  topoSortIt(k, v);
  while (Stack.empty() == false) {
    topoSort.push_back(Stack.top());
    Stack.pop();
  }
  return;
}
bool solve(int v, int k, int n) {
  topoSorting(k, v, n);
  for (int i = 0; i < int(n - 1); i++) {
    bool esVecino = false;
    for (auto w : grafo[topoSort[i]]) {
      if (w.first == topoSort[i + 1] && w.second <= k) esVecino = true;
    }
    if (esVecino)
      continue;
    else
      return false;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  if (n == 2) {
    cout << 1 << endl;
    return 0;
  }
  for (int i = 0; i < int(n); i++) grado[i] = 0;
  for (int i = 0; i < int(m); i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    grafo[u].push_back(make_pair(v, i + 1));
    grado[v]++;
  }
  int maximo = -1;
  for (int i = 0; i < int(n); i++) {
    if (grado[i] == 0 && maximo > -1) {
      cout << -1 << endl;
      return 0;
    } else if (grado[i] == 0) {
      maximo = i;
    }
  }
  bool sePuede = solve(maximo, m, n);
  if (sePuede) {
    int l = 1, r = m;
    while (l + 1 < r) {
      int med = l + (r - l) / 2;
      if (solve(maximo, med, n)) {
        r = med;
      } else {
        l = med;
      }
    }
    cout << r << endl;
  } else {
    cout << -1 << endl;
    return 0;
  }
  return 0;
}
