#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long a[300000];
long long x, y, t;
long long s[300000];
int query(int X, int Y) {
  int g = (X + Y) / 2;
  if (X == Y) {
    return X;
  }
  if (s[X] >= Y - X + 1 && a[X] == t) {
    return -2;
  }
  if (s[X] >= g - X + 1 && a[X] == t) {
    return query(g + 1, Y);
  }
  if (s[g + 1] >= Y - (g + 1) + 1 && a[g + 1] == t) {
    return query(X, g);
  }
  return query(X, g);
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  int k = -1;
  int kk = -1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == k) {
      s[kk]++;
    } else {
      k = a[i];
      kk = i;
      s[kk]++;
    }
  }
  for (int i = 0; i < n; i++) {
    if (s[i] == 0) {
      s[i] = s[i - 1] - 1;
    }
  }
  int d;
  for (int i = 0; i < m; i++) {
    cin >> x >> y >> t;
    x--;
    y--;
    if (x == y && a[x] == t) {
      cout << -1 << endl;
      continue;
    }
    d = query(x, y);
    cout << d + 1 << "\n";
  }
}
