#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
vector<int> pos[maxn];
int num[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    num[i] = a;
    pos[a].push_back(i);
  }
  while (q--) {
    int l, r, x;
    cin >> l >> r >> x;
    l--;
    int t1 = lower_bound(pos[x].begin(), pos[x].end(), l) - pos[x].begin();
    int t2 = lower_bound(pos[x].begin(), pos[x].end(), r) - pos[x].begin();
    if (t2 - t1 == r - l) {
      cout << "-1\n";
      continue;
    }
    if (num[l] != x) {
      cout << l + 1 << "\n";
      continue;
    }
    int lo = l, hi = r + 1;
    while (hi - lo > 1) {
      int mid = (hi + lo) / 2;
      int t = lower_bound(pos[x].begin(), pos[x].end(), mid) - pos[x].begin();
      if (t - t1 != mid - l)
        hi = mid;
      else
        lo = mid;
    }
    cout << hi << "\n";
  }
}
