Problem: You are given array a with n integers and m queries. The i-th query is given with three integers li, ri, xi.

For the i-th query find any position pi (li ≤ pi ≤ ri) so that api ≠ xi.

Input

The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) — the number of elements in a and the number of queries.

The second line contains n integers ai (1 ≤ ai ≤ 106) — the elements of the array a.

Each of the next m lines contains three integers li, ri, xi (1 ≤ li ≤ ri ≤ n, 1 ≤ xi ≤ 106) — the parameters of the i-th query.

Output

Print m lines. On the i-th line print integer pi — the position of any number not equal to xi in segment [li, ri] or the value  - 1 if there is no such number.

Examples

Input

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


Output

2
6
-1
4

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[200005];
int m1[200005][50], m2[200005][50];
pair<int, int> query(int i, int j) {
  int k = int(log(1.0 * j - i) / log(2.0));
  pair<int, int> ret;
  int res = m1[i][k];
  if (a[m1[j - (1 << k) + 1][k]] > a[res]) {
    res = m1[j - (1 << k) + 1][k];
  }
  ret.first = res;
  res = m2[i][k];
  if (a[m2[j - (1 << k) + 1][k]] < a[res]) {
    res = m2[j - (1 << k) + 1][k];
  }
  ret.second = res;
  return ret;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int(i) = (0); (i) < int(n); ++(i)) scanf("%d", a + i);
  for (int(i) = (0); (i) < int(n); ++(i)) m1[i][0] = m2[i][0] = i;
  for (int j = 1; (1 << j) <= n; ++j) {
    for (int i = 0; i + (1 << j) - 1 < n; ++i) {
      if (a[m1[i][j - 1]] > a[m1[i + (1 << (j - 1))][j - 1]])
        m1[i][j] = m1[i][j - 1];
      else
        m1[i][j] = m1[i + (1 << (j - 1))][j - 1];
      if (a[m2[i][j - 1]] < a[m2[i + (1 << (j - 1))][j - 1]])
        m2[i][j] = m2[i][j - 1];
      else
        m2[i][j] = m2[i + (1 << (j - 1))][j - 1];
    }
  }
  int l, r, p;
  for (int(i) = (0); (i) < int(m); ++(i)) {
    scanf("%d %d %d", &l, &r, &p);
    pair<int, int> c = query(l - 1, r - 1);
    if (a[c.first] != p)
      printf("%d\n", c.first + 1);
    else if (a[c.second] != p)
      printf("%d\n", c.second + 1);
    else
      printf("-1\n");
  }
  cin.sync();
  cin.get();
  return 0;
}