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