#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
int a[maxn], pre[maxn];
int find(int x) {
  if (x != pre[x])
    return pre[x] = find(pre[x]);
  else
    return x;
}
void join(int x, int y) {
  int fx = find(x);
  int fy = find(y);
  if (fx != fy) {
    pre[fx] = fy;
  }
  return;
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    pre[i] = i;
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == a[i - 1]) join(i, i - 1);
  }
  while (m--) {
    int l, r, x;
    scanf("%d %d %d", &l, &r, &x);
    int flag = 0;
    while (r >= l) {
      if (a[r] != x) {
        printf("%d\n", r);
        flag = 1;
        break;
      }
      r = find(r) - 1;
    }
    if (!flag) printf("-1\n");
  }
  return 0;
}
