#include <bits/stdc++.h>
const int64_t kMaxSize = static_cast<int64_t>(3e7);
void task_a() {
  int64_t num = 0;
  std::cin >> num;
  std::vector<int64_t> triangles(kMaxSize);
  for (int64_t i = 0; i < kMaxSize; ++i) {
    triangles[i] = i * (i + 1) / 2;
  }
  int pointer = 0;
  while (triangles[pointer] < num) {
    pointer += 1;
  }
  pointer -= 1;
  std::cout << num - triangles[pointer] << std::endl;
}
void task_b() {
  int h = 0, m = 0;
  scanf("%d:%d", &h, &m);
  int add = 0;
  scanf("%d", &add);
  int time = 60 * h + m + add;
  printf("%02d:%02d\n", (time / 60) % 24, time % 60);
}
void task_c() {
  std::ios_base::sync_with_stdio(false);
  int n = 0, m = 0;
  std::cin >> n >> m;
  std::vector<int> nums(n);
  std::vector<int> rightmost_not_equal(n);
  rightmost_not_equal[0] = -1;
  for (int i = 0; i < n; ++i) {
    std::cin >> nums[i];
    if (i > 0) {
      rightmost_not_equal[i] =
          (nums[i] == nums[i - 1]) ? rightmost_not_equal[i - 1] : i - 1;
    }
  }
  for (int i = 0; i < m; ++i) {
    int left = 0, right = 0, x = 0;
    std::cin >> left >> right >> x;
    left -= 1;
    right -= 1;
    if (nums[right] == x && (rightmost_not_equal[right] == -1 ||
                             rightmost_not_equal[right] < left)) {
      std::cout << -1 << std::endl;
    } else if (nums[right] != x) {
      std::cout << right + 1 << std::endl;
    } else {
      std::cout << rightmost_not_equal[right] + 1 << std::endl;
    }
  }
}
int main() {
  task_c();
  return 0;
}
