#include <bits/stdc++.h>
using namespace std;
int Scan() {
  int res = 0, ch, flag = 0;
  if ((ch = getchar()) == '-')
    flag = 1;
  else if (ch >= '0' && ch <= '9')
    res = ch - '0';
  while ((ch = getchar()) >= '0' && ch <= '9') res = res * 10 + ch - '0';
  return flag ? -res : res;
}
void Out(int a) {
  if (a > 9) Out(a / 10);
  putchar(a % 10 + '0');
  putchar('\n');
}
int dp[200005];
int a[200005];
int n, m;
int main() {
  n = Scan();
  m = Scan();
  for (int i = 1; i <= n; i++) a[i] = Scan();
  dp[1] = -1;
  for (int i = 2; i <= n; i++) {
    if (a[i] == a[i - 1])
      dp[i] = dp[i - 1];
    else
      dp[i] = i - 1;
  }
  for (int i = 0; i < m; i++) {
    int l, r, x;
    l = Scan(), r = Scan(), x = Scan();
    if (x != a[r])
      printf("%d\n", r);
    else if (dp[r] >= l)
      printf("%d\n", dp[r]);
    else
      printf("-1\n");
  }
  return (0);
}
