#include <bits/stdc++.h>
using namespace std;
struct Vertex {
  list<Vertex *> into;
  list<Vertex *> from;
  Vertex *parent;
  char visited;
  int n;
};
vector<pair<int, int>> inp;
int n, m;
Vertex vertices[100100];
queue<Vertex *> q;
int nextId[100100];
char visited[100100];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = (0); i < (m); i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    inp.push_back(make_pair(a, b));
    vertices[a - 1].from.push_back(&vertices[b - 1]);
    vertices[b - 1].into.push_back(&vertices[a - 1]);
  }
  Vertex *origin = NULL;
  for (int i = (0); i < (n); i++) {
    vertices[i].visited = 0;
    vertices[i].n = i;
    if (vertices[i].into.size() > 0 || vertices[i].from.size() == 0) continue;
    if (origin != NULL) {
      printf("-1");
      return 0;
    }
    origin = &vertices[i];
  }
  if (origin == NULL) {
    printf("-1");
    return 0;
  }
  memset(nextId, 0, sizeof(nextId));
  memset(visited, 0, sizeof(visited));
  int cnt = 0;
  Vertex *curr = origin;
  while (curr != NULL) {
    cnt++;
    curr->visited = 1;
    Vertex *next = NULL;
    for (auto it = curr->from.begin(); it != curr->from.end(); it++) {
      Vertex *cand = *it;
      if (cand->visited != 0) continue;
      int notVisiedInto = 0;
      for (auto it2 = cand->into.begin(); it2 != cand->into.end(); it2++) {
        Vertex *test = *it2;
        if (test->visited == 0) notVisiedInto++;
      }
      if (notVisiedInto != 0) {
        continue;
      }
      if (next != NULL) {
        printf("-1");
        return 0;
      }
      next = cand;
    }
    nextId[curr->n] = next ? next->n : 0;
    curr = next;
  }
  if (cnt != n) {
    printf("-1");
    return 0;
  }
  int visitedCount = 0, row = 0;
  for (auto it = inp.begin(); it != inp.end(); it++) {
    row++;
    if (nextId[it->first - 1] != it->second - 1) continue;
    if (visited[it->first - 1] == 0) {
      visitedCount++;
      visited[it->first - 1] = 1;
    }
    if (visitedCount == n - 1) {
      printf("%d", row);
      return 0;
    }
  }
  printf("-1");
  return 0;
}
