#include <bits/stdc++.h>
using namespace std;
int a[10000000], b[10000000], memo[10000000], pos[10000000];
int min(int l, int r) {
  if (l <= r) {
    return l;
  }
  return r;
}
int main() {
  int n, m, i, j, k, ind, p, l, x;
  fscanf(stdin, "%d %d", &n, &m);
  for (i = 1; i <= n; i++) {
    fscanf(stdin, "%d", &a[i]);
  }
  i = 1;
  ind = 1;
  while (i <= n) {
    j = i;
    k = a[i];
    memo[ind] = k;
    pos[ind] = i;
    while (j <= n && a[j] == k) {
      b[j] = ind;
      j++;
    }
    i = j;
    ind++;
  }
  for (i = 1; i <= m; i++) {
    fscanf(stdin, "%d %d %d", &p, &l, &x);
    if (b[p] == b[l]) {
      if (x == a[p]) {
        cout << "-1" << endl;
      } else {
        cout << p << endl;
      }
    } else {
      ind = b[p];
      if (memo[b[p]] != x) {
        cout << p << endl;
      } else {
        ind = 1;
        while (pos[b[p] + ind] == x) {
          ind++;
        }
        cout << pos[b[p] + ind] << endl;
      }
    }
  }
  return 0;
}
