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, i, j, m, x, y;
const int N = 1e6 + 7, inf = 2e9 + 7, MOD = 1e9 + 7;
int a[N], l, r;
vector<int> pos[N];
int _fl(int x, int val) {
  int l = 0;
  int r = pos[x].size() - 1;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (pos[x][mid] >= val) {
      r = mid;
    } else {
      l = mid;
    }
  }
  if (pos[x][l] >= val) return l;
  return r;
}
int _fr(int x, int val) {
  int l = 0;
  int r = pos[x].size() - 1;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (pos[x][mid] <= val) {
      l = mid;
    } else {
      r = mid;
    }
  }
  if (pos[x][r] <= val) return r;
  return l;
}
int _find(int _l, int _r, int x) {
  int l = 0;
  int r = _r - _l;
  while (r - l > 1) {
    int mid = (r + l) / 2;
    if (pos[x][_l + mid] - pos[x][_l] == mid) {
      l = mid;
    } else {
      r = mid;
    }
  }
  if (pos[x][_l + r] - pos[x][_l] == r) return pos[x][_l + r];
  return pos[x][_l + l];
}
int main() {
  ios_base::sync_with_stdio(false);
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    pos[a[i]].push_back(i + 1);
  }
  for (i = 0; i < m; i++) {
    scanf("%d%d%d", &l, &r, &x);
    if (pos[x].size() == 0) {
      printf("%d\n", l);
      continue;
    }
    if (l == r && a[l - 1] != x) {
      printf("%d\n", l);
      continue;
    }
    int li = _fl(x, l);
    int ri = _fr(x, r);
    if (r - l == ri - li) {
      puts("-1");
      continue;
    }
    if (pos[x][li] != l) {
      printf("%d\n", l);
      continue;
    }
    int have = _find(li, ri, x);
    printf("%d\n", have + 1);
  }
}