#include <bits/stdc++.h>
using namespace std;
bool isprime(long long int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
vector<long long int> prime;
void sieve(long long int n) {
  bool bakh[n + 1];
  memset(bakh, true, sizeof(bakh));
  for (long long int p = 2; p * p <= n; p++) {
    if (bakh[p] == true) {
      for (long long int i = p * p; i <= n; i += p) bakh[i] = false;
    }
  }
  for (long long int p = 2; p <= n; p++)
    if (bakh[p]) prime.push_back(p);
}
long long int eulertotient(long long int z) {
  long long int fac = z;
  for (long long int i = 0; prime[i] * prime[i] <= z; i++) {
    if (z % prime[i] == 0) {
      fac -= (fac / prime[i]);
      while (z % prime[i] == 0) z /= prime[i];
    }
  }
  if (z > 1) fac -= (fac / z);
  return fac;
}
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long int lcm(long long int a, long long int b) {
  long long int g = gcd(a, b);
  long long int ans = (a * b) / g;
  return ans;
}
long long int modInverse(long long int a, long long int m) {
  long long int hvf = gcd(a, m);
  if (hvf == 1) return power(a, m - 2, m);
  return -1;
}
void multiply(long long int F[2][2], long long int M[2][2]) {
  long long int x = F[0][0] * M[0][0] + F[0][1] * M[1][0];
  long long int y = F[0][0] * M[0][1] + F[0][1] * M[1][1];
  long long int z = F[1][0] * M[0][0] + F[1][1] * M[1][0];
  long long int w = F[1][0] * M[0][1] + F[1][1] * M[1][1];
  F[0][0] = x;
  F[0][1] = y;
  F[1][0] = z;
  F[1][1] = w;
}
void powermat(long long int F[2][2], long long int n) {
  if (n == 0 || n == 1) return;
  long long int M[2][2] = {{1, 1}, {1, 0}};
  powermat(F, n / 2);
  multiply(F, F);
  if (n % 2 != 0) multiply(F, M);
}
long long int fib(long long int n) {
  long long int F[2][2] = {{1, 1}, {1, 0}};
  if (n == 0) return 0;
  powermat(F, n - 1);
  return F[0][0];
}
vector<long long int> merge(vector<long long int> v1,
                            vector<long long int> v2) {
  vector<long long int> temp;
  long long int i = 0, j = 0;
  while (i < v1.size() && j < v2.size()) {
    if (v1[i] < v2[j])
      temp.push_back(v1[i]), i++;
    else
      temp.push_back(v2[j]), j++;
  }
  while (i < v1.size()) temp.push_back(v1[i]), i++;
  while (j < v2.size()) temp.push_back(v2[j]), j++;
  return temp;
}
long long int n, m;
vector<long long int> mark;
vector<long long int> top;
vector<pair<long long int, long long int> > adj[100005];
void dfs(long long int u) {
  mark[u] = 1;
  for (auto v : adj[u]) {
    if (!mark[v.first]) dfs(v.first);
  }
  top.push_back(u);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int a, b;
  cin >> n >> m;
  for (long long int i = 1; i <= m; i++)
    cin >> a >> b, adj[a].push_back({b, i});
  mark.clear();
  mark.resize(n + 1, 0);
  for (long long int i = 1; i <= n; i++) {
    if (!mark[i]) dfs(i);
  }
  bool flag;
  long long int ans = 0;
  for (long long int i = n - 1; i > 0; i--) {
    long long int u = top[i], v = top[i - 1];
    flag = 0;
    for (auto e : adj[u]) {
      if (e.first == v) {
        ans = max(ans, e.second);
        flag = 1;
        break;
      }
    }
    if (!flag) return cout << -1 << endl, 0;
  }
  cout << ans << endl;
}

### Prompt

Please provide a cpp coded solution to the problem described below:

While Farmer John rebuilds his farm in an unfamiliar portion of Bovinia, Bessie is out trying some alternative jobs. In her new gig as a reporter, Bessie needs to know about programming competition results as quickly as possible. When she covers the 2016 Robot Rap Battle Tournament, she notices that all of the robots operate under deterministic algorithms. In particular, robot i will beat robot j if and only if robot i has a higher skill level than robot j. And if robot i beats robot j and robot j beats robot k, then robot i will beat robot k. Since rapping is such a subtle art, two robots can never have the same skill level.

Given the results of the rap battles in the order in which they were played, determine the minimum number of first rap battles that needed to take place before Bessie could order all of the robots by skill level.

Input

The first line of the input consists of two integers, the number of robots n (2 ≤ n ≤ 100 000) and the number of rap battles m (<image>).

The next m lines describe the results of the rap battles in the order they took place. Each consists of two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi), indicating that robot ui beat robot vi in the i-th rap battle. No two rap battles involve the same pair of robots.

It is guaranteed that at least one ordering of the robots satisfies all m relations.

Output

Print the minimum k such that the ordering of the robots by skill level is uniquely defined by the first k rap battles. If there exists more than one ordering that satisfies all m relations, output -1.

Examples

Input

4 5
2 1
1 3
2 3
4 2
4 3


Output

4


Input

3 2
1 2
3 2


Output

-1

Note

In the first sample, the robots from strongest to weakest must be (4, 2, 1, 3), which Bessie can deduce after knowing the results of the first four rap battles.

In the second sample, both (1, 3, 2) and (3, 1, 2) are possible orderings of the robots from strongest to weakest after both rap battles.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool isprime(long long int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
vector<long long int> prime;
void sieve(long long int n) {
  bool bakh[n + 1];
  memset(bakh, true, sizeof(bakh));
  for (long long int p = 2; p * p <= n; p++) {
    if (bakh[p] == true) {
      for (long long int i = p * p; i <= n; i += p) bakh[i] = false;
    }
  }
  for (long long int p = 2; p <= n; p++)
    if (bakh[p]) prime.push_back(p);
}
long long int eulertotient(long long int z) {
  long long int fac = z;
  for (long long int i = 0; prime[i] * prime[i] <= z; i++) {
    if (z % prime[i] == 0) {
      fac -= (fac / prime[i]);
      while (z % prime[i] == 0) z /= prime[i];
    }
  }
  if (z > 1) fac -= (fac / z);
  return fac;
}
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long int lcm(long long int a, long long int b) {
  long long int g = gcd(a, b);
  long long int ans = (a * b) / g;
  return ans;
}
long long int modInverse(long long int a, long long int m) {
  long long int hvf = gcd(a, m);
  if (hvf == 1) return power(a, m - 2, m);
  return -1;
}
void multiply(long long int F[2][2], long long int M[2][2]) {
  long long int x = F[0][0] * M[0][0] + F[0][1] * M[1][0];
  long long int y = F[0][0] * M[0][1] + F[0][1] * M[1][1];
  long long int z = F[1][0] * M[0][0] + F[1][1] * M[1][0];
  long long int w = F[1][0] * M[0][1] + F[1][1] * M[1][1];
  F[0][0] = x;
  F[0][1] = y;
  F[1][0] = z;
  F[1][1] = w;
}
void powermat(long long int F[2][2], long long int n) {
  if (n == 0 || n == 1) return;
  long long int M[2][2] = {{1, 1}, {1, 0}};
  powermat(F, n / 2);
  multiply(F, F);
  if (n % 2 != 0) multiply(F, M);
}
long long int fib(long long int n) {
  long long int F[2][2] = {{1, 1}, {1, 0}};
  if (n == 0) return 0;
  powermat(F, n - 1);
  return F[0][0];
}
vector<long long int> merge(vector<long long int> v1,
                            vector<long long int> v2) {
  vector<long long int> temp;
  long long int i = 0, j = 0;
  while (i < v1.size() && j < v2.size()) {
    if (v1[i] < v2[j])
      temp.push_back(v1[i]), i++;
    else
      temp.push_back(v2[j]), j++;
  }
  while (i < v1.size()) temp.push_back(v1[i]), i++;
  while (j < v2.size()) temp.push_back(v2[j]), j++;
  return temp;
}
long long int n, m;
vector<long long int> mark;
vector<long long int> top;
vector<pair<long long int, long long int> > adj[100005];
void dfs(long long int u) {
  mark[u] = 1;
  for (auto v : adj[u]) {
    if (!mark[v.first]) dfs(v.first);
  }
  top.push_back(u);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int a, b;
  cin >> n >> m;
  for (long long int i = 1; i <= m; i++)
    cin >> a >> b, adj[a].push_back({b, i});
  mark.clear();
  mark.resize(n + 1, 0);
  for (long long int i = 1; i <= n; i++) {
    if (!mark[i]) dfs(i);
  }
  bool flag;
  long long int ans = 0;
  for (long long int i = n - 1; i > 0; i--) {
    long long int u = top[i], v = top[i - 1];
    flag = 0;
    for (auto e : adj[u]) {
      if (e.first == v) {
        ans = max(ans, e.second);
        flag = 1;
        break;
      }
    }
    if (!flag) return cout << -1 << endl, 0;
  }
  cout << ans << endl;
}

```