#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
long long power(long long x, long long y, long long M) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x) % M;
    y >>= 1;
    x = (x * x) % M;
  }
  return res % M;
}
long long power(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y >>= 1;
    x = (x * x);
  }
  return res;
}
const long long mxn = 1e6 + 6, mod = 1e9 + 7, inf = 1e18;
long long t, casee = 1;
long long n, m;
vector<vector<long long>> g(mxn, vector<long long>());
long long vis[mxn];
void dfs(long long st, vector<long long>& top) {
  vis[st] = 1;
  for (long long to : g[st]) {
    if (not vis[to]) dfs(to, top);
  }
  top.push_back(st);
}
vector<long long> topsort() {
  vector<long long> top;
  for (long long i = 0; i < n; i++) {
    if (not vis[i]) {
      dfs(i, top);
    }
  }
  reverse((top).begin(), (top).end());
  return top;
}
void test_case() {
  cin >> n >> m;
  map<pair<long long, long long>, long long> ind;
  for (long long i = 0; i < m; i++) {
    long long u, v;
    cin >> u >> v;
    u--;
    v--;
    g[v].push_back(u);
    ind[{v, u}] = i + 1;
  }
  vector<long long> top = topsort();
  long long chck = 1;
  for (long long i = 0; i < n - 1; i++) {
    long long have = 0;
    for (long long to : g[top[i]]) {
      if (to == top[i + 1]) have = 1;
    }
    if (not have) chck = 0;
  }
  if (chck) {
    long long ans = 0;
    for (long long i = 0; i < n - 1; i++) {
      ans = max(ans, ind[{top[i], top[i + 1]}]);
    }
    cout << ans << "\n";
  } else
    cout << -1 << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  t = 1;
  while (t--) {
    test_case();
    casee++;
  }
  return 0;
}
