#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f, mod = 1e9 + 7;
const int maxn = 1e5 + 100;
const long double PI = acos(-1.0);
long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); }
long long power(long long a, long long n) {
  long long p = 1;
  while (n > 0) {
    if (n % 2) {
      p = p * a;
    }
    n >>= 1;
    a *= a;
  }
  return p;
}
long long power(long long a, long long n, long long mod) {
  long long p = 1;
  while (n > 0) {
    if (n % 2) {
      p = p * a;
      p %= mod;
    }
    n >>= 1;
    a *= a;
    a %= mod;
  }
  return p % mod;
}
int n, m;
vector<int> nex[maxn];
int ru[maxn], flag[maxn], st[maxn];
set<int> gg;
set<int>::iterator it;
int main() {
  while (cin >> n >> m) {
    memset(ru, 0, sizeof(ru));
    gg.clear();
    memset(flag, 0, sizeof(flag));
    int cun = 0, ff = 1, top = 0;
    int sum = 0, k, gu = 0, flv = 0;
    for (int i = 1; i <= m; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      if (flv == 1) continue;
      if (ff == 1 || (flag[u] == 1 && flag[v] == 1)) {
        nex[v].push_back(u);
        if (ru[u] == 0 && ff == -1) {
          gg.erase(u);
        }
        ru[u]++;
      }
      if (flag[u] == 0 && ff == 1) {
        cun++;
        flag[u] = 1;
      }
      if (flag[v] == 0 && ff == 1) {
        cun++;
        flag[v] = 1;
      }
      if (cun == n && ff != -1) ff = 0;
      if (ff == 0) {
        for (int i = 1; i <= n; i++)
          if (ru[i] == 0) st[++top] = i;
        while (top == 1) {
          int s = st[top];
          top--;
          flag[s] = 0;
          sum++;
          for (int i = 0; i < nex[s].size(); i++) {
            ru[nex[s][i]]--;
            if (ru[nex[s][i]] == 0) {
              st[++top] = nex[s][i];
            }
          }
        }
        for (int i = 1; i <= top; i++) gg.insert(st[i]);
        ff = -1;
      }
      if (ff == -1) {
        if (gg.size() == 1) {
          it = gg.begin();
          int ss = *it;
          gg.clear();
          top = 0;
          st[++top] = ss;
          flag[ss] = 0;
          sum++;
          gg.insert(ss);
          while (top == 1) {
            int s = st[top];
            top--;
            gg.erase(s);
            flag[s] = 0;
            sum++;
            for (int i = 0; i < nex[s].size(); i++) {
              ru[nex[s][i]]--;
              if (ru[nex[s][i]] == 0) {
                st[++top] = nex[s][i];
                gg.insert(nex[s][i]);
              }
            }
          }
        }
      }
      if (sum >= n) {
        flv = 1;
        cout << i << endl;
      }
    }
    if (flv == 0) cout << -1 << endl;
  }
  return 0;
}
