#include <bits/stdc++.h>
const long double eps = 1e-9;
using namespace std;
void printVector(const vector<int>& v) {
  printf("%d", v[0]);
  for (int i = 1; i < v.size(); i++) printf(" %d", v[i]);
  cout << endl;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int> > neighbours(n);
  vector<int> indegree(n);
  vector<pair<int, int> > ribs(m);
  for (int i = 0; i < m; i++) {
    cin >> ribs[i].first >> ribs[i].second;
    ribs[i].first--;
    ribs[i].second--;
    indegree[ribs[i].second]++;
    neighbours[ribs[i].first].push_back(ribs[i].second);
  }
  bool does = true;
  vector<int> order;
  vector<bool> vis(n, false);
  queue<int> toProcess;
  for (int i = 0; i < n; i++) {
    if (indegree[i] == 0 && !vis[i]) {
      vis[i] = true;
      order.push_back(i);
      toProcess.push(i);
    }
  }
  int cur = 0;
  while (!toProcess.empty()) {
    if (toProcess.size() != 1) {
      cout << -1 << endl;
      return 0;
    }
    cur = toProcess.front();
    toProcess.pop();
    for (int i = 0; i < neighbours[cur].size(); i++) {
      if (--indegree[neighbours[cur][i]] == 0) {
        vis[neighbours[cur][i]] = true;
        order.push_back(neighbours[cur][i]);
        toProcess.push(neighbours[cur][i]);
      }
    }
  }
  vector<bool> vis2(n - 1);
  map<pair<int, int>, int> ribMap;
  for (int i = 1; i < order.size(); i++) {
    ribMap[make_pair(order[i - 1], order[i])] = i - 1;
  }
  int cnt = 0;
  map<pair<int, int>, int>::iterator itr;
  for (int i = 0; i < m; i++) {
    if ((itr = ribMap.find(ribs[i])) != ribMap.end()) {
      if (!vis2[itr->second]) {
        cnt++;
        vis2[itr->second] = true;
      }
    }
    if (cnt == n - 1) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  return 0;
}
