#include <bits/stdc++.h>
using namespace std;
int n, m;
const int M = 1e5;
vector<int> e[M + 5];
int in[M + 5];
pair<int, int> a[M + 5];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    a[i] = make_pair(x, y);
    e[y].push_back(x);
    in[x]++;
  }
  vector<int> p;
  for (int i = 1; i <= n; i++) {
    if (in[i] == 0) p.push_back(i);
  }
  set<pair<int, int> > s;
  int last = 0;
  for (int i = 1; i <= n; i++) {
    if (p.size() != 1) {
      cout << -1;
      return 0;
    }
    int q = p.back();
    p.pop_back();
    for (int j = 0; j < e[q].size(); j++) {
      int t = e[q][j];
      in[t]--;
      if (in[t] == 0) p.push_back(t);
    }
    if (i > 1) s.insert(make_pair(q, last));
    last = q;
  }
  for (int i = 0; i < m; i++) {
    set<pair<int, int> >::iterator si =
        s.find(make_pair(a[i].first, a[i].second));
    if (si != s.end()) {
      s.erase(si);
      if (s.size() == 0) {
        cout << i + 1 << "\n";
        return 0;
      }
    }
  }
  return 0;
}
