#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int arr[200005];
  int next[200005];
  for (int i = 1; i <= n; i++) {
    next[i] = 200006;
  }
  cin >> arr[1];
  int holding = 1;
  for (int i = 2; i <= n; i++) {
    cin >> arr[i];
    if (arr[i] != arr[holding]) {
      for (int j = holding; j < i; j++) {
        next[j] = i;
      }
      holding = i;
    }
  }
  int l, r, x;
  for (int i = 0; i < m; i++) {
    cin >> l >> r >> x;
    if (arr[l] == x) {
      if (next[l] <= r) {
        cout << next[l] << endl;
      } else
        cout << -1 << endl;
    } else
      cout << l << endl;
  }
}
