#include <bits/stdc++.h>
using namespace std;
const int inf = 2147483647;
const long long linf = 9223372036854775807;
const double Pi = 3.141592653589793;
const int mod = 1000000007;
bool potok = false;
char input;
bool negative;
bool scan(int &x) {
  if (potok) return 0;
  input = getchar();
  negative = 0;
  if (input == EOF) {
    potok = 1;
    return 0;
  }
  while (input == ' ' || input == 10 || input == 11 || input == 14) {
    input = getchar();
  }
  if (input == EOF) {
    potok = 1;
    return 0;
  }
  if (input < '0' && input > '9' && input != '-') return 0;
  if (input == '-') {
    negative = 1;
    input = getchar();
    if (input == EOF) {
      potok = 1;
      return 0;
    }
  }
  if (input < '0' || input > '9') return 0;
  x = 0;
  while (input >= '0' && input <= '9') {
    x = x * 10 + (input - '0');
    input = getchar();
  }
  if (input == EOF) potok = 1;
  x *= (negative ? -1 : 1);
  return 1;
}
bool scan(long long &x) {
  if (potok) return 0;
  input = getchar();
  negative = 0;
  if (input == EOF) {
    potok = 1;
    return 0;
  }
  while (input == ' ' || input == 10 || input == 11 || input == 14) {
    input = getchar();
  }
  if (input == EOF) {
    potok = 1;
    return 0;
  }
  if (input < '0' && input > '9' && input != '-') return 0;
  if (input == '-') {
    negative = 1;
    input = getchar();
    if (input == EOF) {
      potok = 1;
      return 0;
    }
  }
  if (input < '0' || input > '9') return 0;
  x = 0;
  while (input >= '0' && input <= '9') {
    x = x * 10 + (input - '0');
    input = getchar();
  }
  if (input == EOF) potok = 1;
  x *= (negative ? -1 : 1);
  return 1;
}
bool scan(unsigned long long &x) {
  if (potok) return 0;
  input = getchar();
  negative = 0;
  if (input == EOF) {
    potok = 1;
    return 0;
  }
  while (input == ' ' || input == 10 || input == 11 || input == 14) {
    input = getchar();
  }
  if (input == EOF) {
    potok = 1;
    return 0;
  }
  if (input < '0' && input > '9' && input != '-') return 0;
  if (input == '-') {
    negative = 1;
    input = getchar();
    if (input == EOF) {
      potok = 1;
      return 0;
    }
  }
  if (input < '0' || input > '9') return 0;
  x = 0;
  while (input >= '0' && input <= '9') {
    x = x * 10 + (input - '0');
    input = getchar();
  }
  if (input == EOF) potok = 1;
  x *= (negative ? -1 : 1);
  return 1;
}
bool scan(unsigned &x) {
  if (potok) return 0;
  input = getchar();
  negative = 0;
  if (input == EOF) {
    potok = 1;
    return 0;
  }
  while (input == ' ' || input == 10 || input == 11 || input == 14) {
    input = getchar();
  }
  if (input == EOF) {
    potok = 1;
    return 0;
  }
  if (input < '0' && input > '9' && input != '-') return 0;
  if (input == '-') {
    negative = 1;
    input = getchar();
    if (input == EOF) {
      potok = 1;
      return 0;
    }
  }
  if (input < '0' || input > '9') return 0;
  x = 0;
  while (input >= '0' && input <= '9') {
    x = x * 10 + (input - '0');
    input = getchar();
  }
  if (input == EOF) potok = 1;
  x *= (negative ? -1 : 1);
  return 1;
}
bool scan(char &s) {
  if (potok) return 0;
  input = getchar();
  if (input == EOF) {
    potok = 1;
    return 0;
  }
  while (input == ' ' || input == 10 || input == 11 || input == 14) {
    input = getchar();
  }
  if (input == EOF) {
    potok = 1;
    return 0;
  }
  s = input;
  return 1;
}
bool scan(char s[]) {
  if (potok) return 0;
  input = getchar();
  if (input == EOF) {
    potok = 1;
    return 0;
  }
  while (input == ' ' || input == 10 || input == 11 || input == 14) {
    input = getchar();
  }
  if (input == EOF) {
    potok = 1;
    return 0;
  }
  char *t = s;
  while (input != ' ' && input != 10 && input != 11 && input != 14 &&
         input != EOF) {
    *t = input;
    t++;
    input = getchar();
  }
  return 1;
}
bool scan(double &x) {
  if (potok) return 0;
  input = getchar();
  negative = 0;
  if (input == EOF) {
    potok = 1;
    return 0;
  }
  while (input == ' ' || input == 10 || input == 11 || input == 14) {
    input = getchar();
  }
  if (input == EOF) {
    potok = 1;
    return 0;
  }
  if (input < '0' && input > '9' && input != '-') return 0;
  if (input == '-') {
    negative = 1;
    input = getchar();
    if (input == EOF) {
      potok = 1;
      return 0;
    }
  }
  if (input < '0' || input > '9') return 0;
  x = 0.0;
  register bool f = 0;
  register int h = 10;
  while ((input >= '0' && input <= '9') || (input == '.' && !f)) {
    if (input == '.') {
      f = 1;
      input = getchar();
      if (input == EOF) {
        potok = 1;
        return 0;
      }
    }
    if (f) {
      x += double(input - '0') / h;
      h *= 10;
    } else
      x = x * 10 + (input - '0');
    input = getchar();
  }
  x *= (negative ? -1 : 1);
  return 1;
}
template <typename X>
void getarr(X *a, int n) {
  for (int i = 0; i < n; i++) scan(a[i]);
}
void getarr(string *a, int n) {
  for (int i = 0; i < n; i++) cin >> a[i];
}
template <typename X>
void putarr(X *a, int n, char ch = ' ') {
  for (int i = 0; i < n; i++) cout << a[i] << ch;
}
inline bool XOR(bool p, bool q) { return ((p || q) && !(p && q)); }
template <typename X>
inline X abs(X a) {
  return a < 0 ? -1 * a : a;
}
template <typename T>
inline auto sqr(T a) -> decltype(a * a) {
  return a * a;
}
template <typename T>
inline auto cub(T a) -> decltype(a * a * a) {
  return a * a * a;
}
inline void swap(int &a, int &b) {
  a ^= b;
  b ^= a;
  a ^= b;
}
inline void swap(unsigned &a, unsigned &b) {
  a ^= b;
  b ^= a;
  a ^= b;
}
inline void swap(long long &a, long long &b) {
  a ^= b;
  b ^= a;
  a ^= b;
}
inline void swap(unsigned long long &a, unsigned long long &b) {
  a ^= b;
  b ^= a;
  a ^= b;
}
template <typename T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <typename X>
int binf(X *a, int l, int r, X p) {
  while (l < r) {
    int m = (l + r) >> 1;
    if (p > a[m])
      l = m + 1;
    else
      r = m;
  }
  if (a[l] == p)
    return l;
  else
    return -1;
}
template <typename X>
X gcd(X a, X b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
template <typename X>
X gcd(X a, X b, X &x, X &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  X x1, y1;
  X d = gcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return d;
}
template <typename X>
X binpow(X a, int n, int m = 0) {
  X res = 1;
  if (m) res %= m;
  while (n) {
    if (n & 1) {
      res *= a;
      if (m) res %= m;
    }
    a *= a;
    if (m) a %= m;
    n >>= 1;
  }
  return res;
}
pair<int, int> r[100000];
int m1;
int n;
bool mpq(int m) {
  vector<int> g[n], c(n);
  for (int i = 0; i < m; i++) c[r[i].second]++;
  for (int i = 0; i < m; i++) {
    g[r[i].first].push_back(r[i].second);
  }
  queue<int> q;
  for (int i = 0; i < n; i++)
    if (c[i] == 0) q.push(i);
  while (!q.empty()) {
    int x = q.front();
    if (q.size() > 1) return 0;
    q.pop();
    for (int y : g[x]) {
      c[y]--;
      if (c[y] == 0) q.push(y);
    }
  }
  return 1;
}
int main() {
  ios::sync_with_stdio(0);
  scan(n);
  scan(m1);
  for (int i = 0; i < m1; i++) {
    int u, v;
    scan(u);
    scan(v);
    u--;
    v--;
    r[i] = {u, v};
  }
  if (!mpq(m1)) {
    cout << -1;
    return 0;
  }
  int a = 0, b = m1 - 1;
  while (a < b) {
    int h = (a + b) / 2;
    if (mpq(h + 1))
      b = h;
    else
      a = h + 1;
  }
  cout << a + 1;
  return 0;
}
