#include <bits/stdc++.h>
using namespace std;
int N, M, a[200005], dp[200005];
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= N; i++) scanf("%d", &a[i]);
  dp[1] = 0;
  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;
    scanf("%d%d%d", &l, &r, &x);
    if (a[r] == x)
      printf("%d\n", (dp[r] < l ? -1 : dp[r]));
    else
      printf("%d\n", r);
  }
  return 0;
}
