#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int a[N], app[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cerr.tie(nullptr);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 2; i <= n; i++) {
    if (a[i] != a[i - 1])
      app[i] = i - 1;
    else
      app[i] = app[i - 1];
  }
  for (int i = 1; i <= m; i++) {
    int l, r, x;
    cin >> l >> r >> x;
    if (x != a[r]) {
      cout << r << endl;
      continue;
    }
    if (app[r] < l)
      cout << -1 << endl;
    else
      cout << app[r] << endl;
  }
  return 0;
}
