#include <bits/stdc++.h>
using namespace std;
const long double PI = 4 * atan((long double)1);
const long long mod = 1e9 + 7;
const long long inf = 922337203685477;
const long long nax = 1e5 + 5;
long long n, m;
long long deg[nax], pos[nax];
pair<long long, long long> edge[nax];
vector<vector<long long>> v(nax);
void reset() {
  for (long long i = 1; i <= n; i++) {
    deg[i] = 0;
    pos[i] = 0;
    v[i].clear();
  }
}
long long cek(long long lim) {
  reset();
  set<pair<long long, long long>> st;
  for (long long i = 1; i <= lim; i++) {
    auto cur = edge[i];
    v[cur.first].push_back(cur.second);
    deg[cur.second]++;
    st.insert({cur.first, cur.second});
  }
  queue<long long> q;
  for (long long i = 1; i <= n; i++) {
    if (!deg[i]) q.push(i);
  }
  long long len = 0;
  while (!q.empty()) {
    auto cur = q.front();
    q.pop();
    pos[++len] = cur;
    for (auto it : v[cur]) {
      deg[it]--;
      if (deg[it] == 0) {
        q.push(it);
      }
    }
  }
  if (len != n) {
    return 0;
  }
  for (long long i = 1; i <= n; i++) {
    if (deg[i]) {
      return 0;
    }
  }
  for (long long i = 1; i < n; i++) {
    if (!st.count({pos[i], pos[i + 1]})) {
      return 0;
    }
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  for (long long i = 1; i <= m; i++) {
    cin >> edge[i].first >> edge[i].second;
  }
  long long l = 1, r = m, ret = inf;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (cek(mid)) {
      ret = min(ret, mid);
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  if (ret == inf) ret = -1;
  cout << ret << '\n';
}
