#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-9;
const long long mod = 1e9 + 7;
const unsigned long long mx = 1333333331;
inline void RI(int &x) {
  char c;
  while ((c = getchar()) < '0' || c > '9')
    ;
  x = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0';
}
struct Edge {
  int v, next;
} edge[100005];
int head[100005];
int deg[100005];
int tot;
set<pair<int, int> > s;
pair<int, int> j[100005];
void init() {
  memset(head, -1, sizeof(head));
  memset(deg, 0, sizeof(deg));
  s.clear();
  tot = 0;
}
void add_edge(int a, int b) {
  edge[tot] = (Edge){b, head[a]};
  head[a] = tot++;
}
int main() {
  int n, m;
  while (cin >> n >> m) {
    init();
    for (int i = 0; i < m; i++) {
      int a, b;
      scanf("%d%d", &a, &b);
      add_edge(a, b);
      j[i] = make_pair(a, b);
      deg[b]++;
    }
    int flag = 0;
    int ret = 0;
    int tmp = 0;
    queue<int> q;
    for (int i = 1; i <= n; i++) {
      if (!deg[i]) {
        ret++;
        q.push(i);
      }
    }
    if (ret > 1) flag = 1;
    if (flag)
      printf("-1\n");
    else {
      while (!q.empty()) {
        int u = q.front();
        q.pop();
        tmp++;
        ret = 0;
        for (int i = head[u]; i != -1; i = edge[i].next) {
          int v = edge[i].v;
          deg[v]--;
          if (deg[v] == 0) {
            s.insert(make_pair(u, v));
            q.push(v);
            ret++;
          }
        }
        if (ret > 1) flag = 1;
      }
      if (flag || tmp != n)
        printf("-1\n");
      else {
        int ans = 0;
        for (int i = 0; i < m; i++) {
          if (s.count(j[i])) ans++;
          if (ans == n - 1) {
            printf("%d\n", i + 1);
            break;
          }
        }
      }
    }
  }
  return 0;
}
