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