#include <bits/stdc++.h>
using namespace std;
int brcaleta[333555], brdece[333555];
vector<int> adj[333555], adjcalci[333555];
set<int> nemacaleta, nemadece;
bool mark[333555];
int main() {
  int n, m, i, j, x, y, uk;
  bool bb;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) {
    brcaleta[i] = 0;
    brdece[i] = 0;
    nemacaleta.insert(i);
    nemadece.insert(i);
    adj[i].clear();
    adjcalci[i].clear();
    mark[i] = false;
  }
  uk = n;
  for (i = 1; i <= m; i++) {
    scanf("%d %d", &x, &y);
    if (mark[x]) continue;
    if (mark[y]) continue;
    adj[x].push_back(y);
    adjcalci[y].push_back(x);
    if (brdece[x] == 0) {
      nemadece.erase(x);
    }
    brdece[x]++;
    if (brcaleta[y] == 0) {
      nemacaleta.erase(y);
    }
    brcaleta[y]++;
    while (true) {
      bb = false;
      if (nemacaleta.size() == 1) {
        x = *nemacaleta.begin();
        mark[x] = true;
        nemacaleta.erase(x);
        for (j = 0; j < adj[x].size(); j++) {
          y = adj[x][j];
          if (!mark[y]) {
            brcaleta[y]--;
            if (brcaleta[y] == 0) {
              nemacaleta.insert(y);
            }
          }
        }
        uk--;
        bb = true;
      }
      if (nemadece.size() == 1) {
        y = *nemadece.begin();
        mark[y] = true;
        nemadece.erase(y);
        for (j = 0; j < adjcalci[y].size(); j++) {
          x = adjcalci[y][j];
          if (!mark[x]) {
            brdece[x]--;
            if (brdece[x] == 0) nemadece.insert(x);
          }
        }
        uk--;
        bb = true;
      }
      if (!bb) break;
    }
    if (uk <= 1) {
      printf("%d\n", i);
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}
