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, x;
set<int> temp_pos[1000005];
vector<int> posisi[1000005];
set<int> bilangan;
int cariLow(int idxPos, int bawah, int atas, int val) {
  if (bawah > atas) return bawah;
  if (val <= posisi[idxPos][(atas + bawah) / 2])
    return cariLow(idxPos, bawah, (atas + bawah) / 2 - 1, val);
  else
    return cariLow(idxPos, (atas + bawah) / 2 + 1, atas, val);
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    temp_pos[x].insert(i + 1);
    bilangan.insert(x);
  }
  for (set<int>::iterator i = bilangan.begin(); i != bilangan.end(); i++) {
    posisi[*i] = vector<int>(temp_pos[*i].begin(), temp_pos[*i].end());
  }
  for (int i = 0; i < m; i++) {
    int l, r;
    scanf("%d %d %d", &l, &r, &x);
    if (posisi[x].size() > 0) {
      int l2 = cariLow(x, 0, posisi[x].size() - 1, l),
          r2 = cariLow(x, 0, posisi[x].size() - 1, r);
      if (r2 >= posisi[x].size()) r2--;
      if (posisi[x][r2] > r && r2 >= 0) r2--;
      if (l2 > r2)
        printf("%d\n", l);
      else if (r2 - l2 == r - l)
        printf("-1\n");
      else {
        int a2 = l2, b2 = r2;
        while (a2 <= b2) {
          if (posisi[x][(a2 + b2) / 2] > l + ((a2 - l2) + (b2 - l2)) / 2)
            b2 = (a2 + b2) / 2 - 1;
          else
            a2 = (a2 + b2) / 2 + 1;
        }
        printf("%d\n", a2 - l2 + l);
      }
    } else
      printf("%d\n", l);
  }
  return 0;
}