#include <bits/stdc++.h>
constexpr long long inf = (long long)1e9 + 7ll;
char buff[(int)1e6 + 17];
inline void config_io(const bool& __fastio) {
  if (__fastio) {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
  }
  if (!std::string("").empty()) {
    assert(
        freopen(""
                ".in",
                "r", stdin));
    assert(
        freopen(""
                ".out",
                "w", stdout));
  }
}
using namespace std;
const int maxn = (int)2e5 + 17;
int n, q;
int arr[maxn], logn[maxn];
int mins[20][maxn], mini[20][maxn], maxs[20][maxn], maxi[20][maxn];
void build() {
  for (int i = 1, l = 0; i <= n; ++i) {
    l += ((1 << (l + 1)) == i);
    logn[i] = l;
  }
  for (int k = 1; k <= logn[n]; ++k)
    for (int i = 0; i + (1 << (k - 1)) < n; ++i) {
      mins[k][i] = min(mins[k - 1][i], mins[k - 1][i + (1 << (k - 1))]);
      mini[k][i] = mins[k - 1][i] == mins[k][i]
                       ? mini[k - 1][i]
                       : mini[k - 1][i + (1 << (k - 1))];
      maxs[k][i] = max(maxs[k - 1][i], maxs[k - 1][i + (1 << (k - 1))]);
      maxi[k][i] = maxs[k - 1][i] == maxs[k][i]
                       ? maxi[k - 1][i]
                       : maxi[k - 1][i + (1 << (k - 1))];
    }
}
int getmin(int l, int r) {
  int k = logn[r - l + 1];
  return min(mins[k][l], mins[k][r - (1 << k) + 1]);
}
int getmax(int l, int r) {
  int k = logn[r - l + 1];
  return max(maxs[k][l], maxs[k][r - (1 << k) + 1]);
}
int getminid(int l, int r) {
  int k = logn[r - l + 1];
  return mins[k][l] < mins[k][r - (1 << k) + 1] ? mini[k][l]
                                                : mini[k][r - (1 << k) + 1];
}
int getmaxid(int l, int r) {
  int k = logn[r - l + 1];
  return maxs[k][l] > maxs[k][r - (1 << k) + 1] ? maxi[k][l]
                                                : maxi[k][r - (1 << k) + 1];
}
int main() {
  config_io(false);
  scanf("%d %d", &n, &q);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &arr[i]);
    mins[0][i] = maxs[0][i] = arr[i];
    mini[0][i] = maxi[0][i] = i;
  }
  build();
  for (int i = 0; i < q; ++i) {
    int l, r, x;
    scanf("%d %d %d", &l, &r, &x);
    --l, --r;
    if (getmin(l, r) == x && getmax(l, r) == x) {
      printf("-1\n");
      continue;
    }
    if (getmin(l, r) == x)
      printf("%d\n", getmaxid(l, r) + 1);
    else
      printf("%d\n", getminid(l, r) + 1);
  }
  return 0;
}
