#include <bits/stdc++.h>
using namespace std;
int num[200005], pos[200005];
int main() {
  int n, p;
  scanf("%d%d", &n, &p);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &num[i]);
    if (num[i] == num[i - 1])
      pos[i] = pos[i - 1];
    else
      pos[i] = i;
  }
  while (p--) {
    int l, r, x;
    scanf("%d%d%d", &l, &r, &x);
    if (num[r] == x && pos[l] == pos[r])
      printf("-1\n");
    else {
      if (num[r] != x)
        printf("%d\n", r);
      else
        printf("%d\n", pos[r] - 1);
    }
  }
  return 0;
}
