#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int> > > G;
int z = 0;
int in_degrees[100000] = {0};
int discovered_in_degrees[100000] = {0};
int main() {
  int n, m;
  cin >> n >> m;
  G = vector<vector<pair<int, int> > >(n, vector<pair<int, int> >(0));
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    in_degrees[b]++;
    G[a].push_back({b, i});
  }
  int vert = -1;
  for (int i = 0; i < n; i++) {
    if (in_degrees[i] == 0)
      if (vert == -1)
        vert = i;
      else {
        cout << "-1\n";
        return 0;
      }
  }
  for (int i = 0; i < n; i++) {
    for (auto v : G[vert]) {
      discovered_in_degrees[v.first]++;
    }
    int next_vert = -1;
    for (auto v : G[vert]) {
      if (discovered_in_degrees[v.first] == in_degrees[v.first]) {
        if (next_vert == -1) {
          next_vert = v.first;
          z = max(z, v.second);
        } else {
          cout << "-1\n";
          return 0;
        }
      }
    }
    vert = next_vert;
  }
  cout << z + 1 << endl;
}
