#include <bits/stdc++.h>
using namespace std;
struct interval {
  int start;
  int val;
};
interval V[200000 + 4];
int offset[200000 + 4];
int main() {
  ios::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  offset[0] = 0;
  int Vi = 0;
  int start = 0, start_v;
  cin >> start_v;
  interval iv;
  for (int i = 1; i < n; i++) {
    int x;
    cin >> x;
    if (x == start_v)
      offset[i] = offset[i - 1];
    else {
      iv.start = start;
      iv.val = start_v;
      V[Vi] = (iv);
      Vi++;
      start = i;
      start_v = x;
      offset[i] = offset[i - 1] + 1;
    }
  }
  iv.start = start;
  iv.val = start_v;
  V[Vi] = (iv);
  for (int i = 0; i < m; i++) {
    int l, r, x;
    cin >> l >> r >> x;
    l--;
    r--;
    if (offset[l] == offset[r] && V[offset[l]].val == x)
      printf("-1\n");
    else {
      if (offset[l] == offset[r])
        printf("%d\n", l + 1);
      else if (V[offset[l]].val == x)
        printf("%d\n", V[offset[l] + 1].start + 1);
      else
        printf("%d\n", l + 1);
    }
  }
  return 0;
}
