#include <bits/stdc++.h>
using namespace std;
const int INF = (-1u) / 2;
const long long int INF2 = (-1ull) / 2;
int a, b, i, c[1011000], j, k, n, m, timer = 0, l, r, x, y;
int cnt = 0, fl = 0, a2, a3 = -1000000, ans = 0;
pair<int, int> t[1000100], t2[1000100], p1, p2;
void build(int v, int tl, int tr) {
  if (tl == tr) {
    t[v] = make_pair(c[tl], tl);
    t2[v] = make_pair(c[tl], tl);
  } else {
    int tm = ((tl + tr) >> 1);
    build((v << 1), tl, tm);
    build((v << 1) + 1, tm + 1, tr);
    t[v] = min(t[(v << 1)], t[(v << 1) + 1]);
    t2[v] = max(t2[(v << 1)], t2[(v << 1) + 1]);
  }
}
pair<int, int> takemn(int v, int tl, int tr, int l, int r) {
  if (l > r)
    return make_pair(1000001, 1000001);
  else if (tl == l && tr == r)
    return t[v];
  else {
    int tm = ((tl + tr) >> 1);
    return min(takemn((v << 1), tl, tm, l, min(r, tm)),
               takemn((v << 1) + 1, tm + 1, tr, max(l, tm + 1), r));
  }
}
pair<int, int> takemx(int v, int tl, int tr, int l, int r) {
  if (l > r)
    return make_pair(-1, 1000001);
  else if (tl == l && tr == r)
    return t2[v];
  else {
    int tm = ((tl + tr) >> 1);
    return max(takemx((v << 1), tl, tm, l, min(r, tm)),
               takemx((v << 1) + 1, tm + 1, tr, max(l, tm + 1), r));
  }
}
int main() {
  scanf("%d%d", &n, &k);
  for (i = 1; i <= n; i++) {
    scanf("%d", &c[i]);
  }
  build(1, 1, n);
  for (i = 0; i < k; i++) {
    scanf("%d%d%d", &l, &r, &x);
    p1 = takemn(1, 1, n, l, r);
    if (p1.first >= 1 && p1.first <= 1000000 && p1.first != x) {
      printf("%d\n", p1.second);
      continue;
    }
    p2 = takemx(1, 1, n, l, r);
    if (p2.first >= 1 && p2.first <= 1000000 && p2.first != x)
      printf("%d\n", p2.second);
    else
      printf("-1\n");
  }
  return 0;
}
