#include <bits/stdc++.h>
using namespace std;
void TopSort(const vector<vector<int> >& G, int node, vector<bool>& done,
             vector<int>& order) {
  done[node] = true;
  for (int i = 0; i < G[node].size(); ++i) {
    int other = G[node][i];
    if (done[other]) {
      continue;
    }
    TopSort(G, other, done, order);
  }
  order.push_back(node);
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int> > G(n);
  vector<pair<int, int> > edges;
  for (int i = 0; i < m; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    --u;
    --v;
    edges.push_back(make_pair(u, v));
    G[u].push_back(v);
  }
  vector<bool> done(n, false);
  vector<int> order;
  for (int i = 0; i < n; ++i) {
    if (!done[i]) {
      TopSort(G, i, done, order);
    }
  }
  reverse(order.begin(), order.end());
  set<pair<int, int> > all_edges(edges.begin(), edges.end());
  bool defined = true;
  for (int i = 0; i + 1 < order.size(); ++i) {
    if (!all_edges.count(make_pair(order[i], order[i + 1]))) {
      defined = false;
      break;
    }
  }
  if (!defined) {
    cout << -1 << endl;
    return 0;
  }
  set<pair<int, int> > needed_edges;
  for (int i = 0; i + 1 < order.size(); ++i) {
    needed_edges.insert(make_pair(order[i], order[i + 1]));
  }
  int result = 0;
  for (int i = 0; i < edges.size(); ++i) {
    if (needed_edges.count(edges[i])) {
      needed_edges.erase(edges[i]);
    }
    if (needed_edges.empty()) {
      result = i + 1;
      break;
    }
  }
  cout << result << endl;
  return 0;
}
