#include <bits/stdc++.h>
int main() {
  int a[200001], z[200001];
  int n, m, i, l, r, x;
  scanf("%d %d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  z[1] = 1;
  for (i = 2; i <= n; i++) {
    if (a[i] == a[i - 1])
      z[i] = z[i - 1];
    else
      z[i] = i;
  }
  for (i = 1; i <= m; i++) {
    scanf("%d%d%d", &l, &r, &x);
    if (x != a[r])
      printf("%d\n", r);
    else if (z[r] > z[l])
      printf("%d\n", z[r] - 1);
    else
      printf("-1\n");
  }
}
