#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
int n, m, a[1000111], d[1000111];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    if (a[i] != a[i - 1])
      d[i] = i - 1;
    else
      d[i] = d[i - 1];
  }
  for (int i = 1; i <= m; i++) {
    int l, r, x;
    cin >> l >> r >> x;
    if (a[r] != x)
      cout << r << '\n';
    else {
      if (d[r] >= l)
        cout << d[r] << '\n';
      else
        cout << -1 << '\n';
    }
  }
}
