#include <bits/stdc++.h>
using namespace std;
pair<int, int> tree[200005 * 4];
int arr[200005];
pair<int, int> merge(pair<int, int> p1, pair<int, int> p2) {
  if (p1.first != -1 && p1.second != -1) {
    return p1;
  }
  if (p2.second != -1 && p2.first != -1) {
    return p2;
  }
  if (p1.first == -1) {
    return p2;
  }
  if (p2.first == -1) {
    return p1;
  }
  if (arr[p1.first] == arr[p2.first]) {
    return p1;
  } else {
    p1.second = p2.first;
    return p1;
  }
}
void init(int node, int a, int b) {
  if (a > b) {
    return;
  }
  if (a == b) {
    tree[node].first = a;
    tree[node].second = -1;
    return;
  }
  init(2 * node, a, (a + b) / 2);
  init(2 * node + 1, (a + b) / 2 + 1, b);
  tree[node] = merge(tree[node * 2], tree[node * 2 + 1]);
}
pair<int, int> query(int node, int a, int b, int i, int j) {
  if (a > b || a > j || b < i) {
    pair<int, int> ret;
    ret.first = ret.second = -1;
    return ret;
  }
  if (a >= i && b <= j) {
    return tree[node];
  }
  pair<int, int> q1 = query(node * 2, a, (a + b) / 2, i, j);
  pair<int, int> q2 = query(2 * node + 1, (a + b) / 2 + 1, b, i, j);
  return merge(q1, q2);
}
int main() {
  int n, m, i, j, k, l, r, x;
  scanf("%d %d", &n, &m);
  for (i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
  }
  init(1, 0, n - 1);
  for (i = 0; i < m; i++) {
    scanf("%d %d %d", &l, &r, &x);
    pair<int, int> q = query(1, 0, n - 1, l - 1, r - 1);
    if (arr[q.first] == x) {
      if (q.second != -1) {
        q.second++;
      }
      printf("%d\n", q.second);
    } else {
      q.first++;
      printf("%d\n", q.first);
    }
  }
  return 0;
}
