#include <bits/stdc++.h>
using namespace std;
int used[100500], ch = 1, n, m;
int a[100500], b[100500];
set<int> g[100500];
vector<int> ans;
void dfs(int v) {
  used[v] = ch;
  set<int>::iterator it;
  for (it = g[v].begin(); it != g[v].end(); it++) {
    if (ch != used[(*it)]) dfs((*it));
  }
  ans.push_back(v);
}
bool pr(int nom) {
  ans.clear();
  for (int i = 1; i <= n; i++) {
    g[i].clear();
  }
  for (int i = 0; i < nom; i++) {
    g[a[i]].insert(b[i]);
  }
  for (int i = 1; i <= n; i++) {
    if (used[i] != ch) {
      dfs(i);
    }
  }
  ch++;
  for (int i = 1; i < n; i++) {
    if (g[ans[i]].find(ans[i - 1]) == g[ans[i]].end()) {
      return false;
    }
  }
  return true;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
  }
  int l = 1, r = m;
  if (!pr(m)) {
    cout << -1;
    return 0;
  }
  if (n == 2) {
    cout << 1;
    return 0;
  }
  while (r - l > 1) {
    if (pr((r + l) / 2)) {
      r = (r + l) / 2;
    } else {
      l = (r + l) / 2;
    }
  }
  cout << r;
}
