#include <bits/stdc++.h>
int n, m, a[200002], p[200002];
int main() {
  int l, r, x, ans;
  scanf("%d%d", &n, &m);
  p[0] = -1;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    p[i] = (a[i] != a[i - 1]) ? i - 1 : p[i - 1];
  }
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d%d", &l, &r, &x);
    ans = (a[r] != x) ? r : ((p[r] < l) ? -1 : p[r]);
    printf("%d\n", ans);
  }
  return 0;
}
