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;
const int mx = 2e5 + 10;
const double eps = 1e-9;
const int inf = 1e9;
const int N = 1e6 + 3;
int a[mx];
int n;
long long seg1[mx << 2], seg2[mx << 2];
void build1(int nd, int L, int R) {
  if (L == R) {
    seg1[nd] = a[L];
    return;
  }
  int mid = (L + R) / 2;
  build1(nd << 1, L, mid);
  build1(nd << 1 | 1, mid + 1, R);
  seg1[nd] = max(seg1[nd << 1], seg1[nd << 1 | 1]);
}
long long query1(int nd, int L, int R, int from, int to) {
  if (from <= L && R <= to) return seg1[nd];
  if (from > R || to < L) return -inf;
  int mid = (L + R) >> 1;
  long long leftAns = query1(nd << 1, L, mid, from, to);
  long long rightAns = query1(nd << 1 | 1, mid + 1, R, from, to);
  return max(leftAns, rightAns);
}
void build2(int nd, int L, int R) {
  if (L == R) {
    seg2[nd] = a[L];
    return;
  }
  int mid = (L + R) >> 1;
  build2(nd << 1, L, mid);
  build2(nd << 1 | 1, mid + 1, R);
  seg2[nd] = min(seg2[nd << 1], seg2[nd << 1 | 1]);
}
long long query2(int nd, int L, int R, int from, int to) {
  if (from <= L && R <= to) return seg2[nd];
  if (from > R || to < L) return inf;
  int mid = (L + R) >> 1;
  long long leftAns = query2(nd << 1, L, mid, from, to);
  long long rightAns = query2(nd << 1 | 1, mid + 1, R, from, to);
  return min(leftAns, rightAns);
}
vector<int> adj[N];
int main() {
  int q;
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    adj[a[i]].push_back(i);
  }
  build1(1, 1, n);
  build2(1, 1, n);
  while (q--) {
    int l, r, x;
    scanf("%d%d%d", &l, &r, &x);
    int i = query1(1, 1, n, l, r);
    int j = query2(1, 1, n, l, r);
    int p = lower_bound(adj[i].begin(), adj[i].end(), l) - adj[i].begin();
    int q = lower_bound(adj[j].begin(), adj[j].end(), l) - adj[j].begin();
    if (i != x && adj[i][p] <= r) {
      printf("%d\n", adj[i][p]);
    } else if (j != x && adj[j][q] <= r) {
      printf("%d\n", adj[j][q]);
    } else
      printf("-1\n");
  }
}