#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod) {
  x += y;
  if (x >= mod) x -= mod;
}
void et() {
  puts("-1");
  exit(0);
}
int dg[100005], cnt;
set<int> sp;
vector<int> mp[100005];
bool vis[100005];
void fmain() {
  scanf("%d%d", &n, &m);
  for (int(i) = 1; (i) <= (int)(n); (i)++) sp.insert(i);
  int u, v;
  for (int(i) = 1; (i) <= (int)(m); (i)++) {
    scanf("%d%d", &u, &v);
    if (vis[u]) continue;
    mp[u].push_back(v);
    dg[v]++;
    if (dg[v] == 1) sp.erase(v);
    while (sp.size() == 1) {
      cnt++;
      int root = *sp.begin();
      sp.clear();
      vis[root] = 1;
      for (int c : mp[root]) {
        dg[c]--;
        if (dg[c] == 0) sp.insert(c);
      }
    }
    if (cnt == n) {
      printf("%d\n", i);
      return;
    }
  }
  puts("-1");
}
int main() {
  fmain();
  return 0;
}
