#include <bits/stdc++.h>
using namespace std;
map<int, pair<int, int>> pos;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int cur, start = 1;
  scanf("%d", &cur);
  for (int i = 2; i <= n; i++) {
    int a;
    scanf("%d", &a);
    if (a != cur) {
      for (int j = start; j < i; j++) pos[j] = make_pair(i - 1, cur);
      cur = a;
      start = i;
    }
  }
  for (int j = start; j <= n; j++) pos[j] = make_pair(n, cur);
  while (m--) {
    int l, r, x;
    scanf("%d%d%d", &l, &r, &x);
    if (pos[l].second == x) {
      if (pos[l].first < r)
        printf("%d\n", pos[l].first + 1);
      else
        puts("-1");
    } else
      printf("%d\n", l);
  }
  return 0;
}
