#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  int a[200005];
  for (int i = 1; i <= n; i++) cin >> a[i];
  int z[200002];
  z[0] = 0;
  z[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (a[i - 1] == a[i])
      z[i] = z[i - 1];
    else
      z[i] = i;
  }
  for (int i = 0; i < m; i++) {
    int l, r, x;
    cin >> l >> r >> x;
    if (a[r] == x) {
      if (z[r] - 1 >= l) {
        cout << z[r] - 1 << "\n";
      } else
        cout << "-1\n";
    } else
      cout << r << "\n";
  }
  return 0;
}
