#include <bits/stdc++.h>
using namespace std;
int pos[200205], a[200205];
int main() {
  ios::sync_with_stdio(false);
  int n, m, l, r, x;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    if (a[i] != a[i - 1])
      pos[i] = ((i - 1) == 0) ? -1 : i - 1;
    else
      pos[i] = pos[i - 1];
  }
  while (m--) {
    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");
  }
}
