#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:536870912")
const int MOD = 1000000007;
const int INF = 1000000001;
const int MAXN = 17;
const long double EPS = 1e-6;
const int HASH_POW = 29;
const long double PI = acos(-1.0);
using namespace std;
void my_return(int code) { exit(code); }
int n, m;
struct edge {
  int to, timer;
  edge(int _to, int _timer) {
    to = _to;
    timer = _timer;
  }
};
vector<edge> G[100010];
char u[100010];
vector<int> ord;
void dfs(int v, int mx) {
  u[v] = 1;
  for (int i = 0; i < G[v].size(); ++i) {
    if (!u[G[v][i].to] && G[v][i].timer <= mx) dfs(G[v][i].to, mx);
  }
  ord.push_back(v);
}
bool check(int ptr, int mx) {
  while (true) {
    if (ptr == 0) return true;
    int v = ord[ptr], to = ord[ptr - 1];
    bool good = false;
    for (int i = 0; i < G[v].size(); ++i) {
      if (G[v][i].to == to && G[v][i].timer <= mx) {
        good = true;
        break;
      }
    }
    if (!good) return false;
    --ptr;
  }
  return false;
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  mt19937 mt_rand(time(0));
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    G[u].push_back(edge(v, i));
  }
  int ll = 0, rr = m + 1;
  while (ll + 1 < rr) {
    int mid = (ll + rr) / 2;
    ord.clear();
    memset(u, 0, sizeof u);
    for (int i = 1; i <= n; ++i)
      if (!u[i]) dfs(i, mid);
    if (check(n - 1, mid))
      rr = mid;
    else
      ll = mid;
  }
  if (rr == m + 1)
    printf("-1\n");
  else
    printf("%d\n", rr);
  my_return(0);
}
