#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 4, M = N * 20;
int sum[M], ls[M], rs[M], root[N], sz, n;
void update(int &x, int y, int l, int r, int val) {
  x = ++sz;
  sum[x] = sum[y] + 1;
  ls[x] = ls[y];
  rs[x] = rs[y];
  int mid = (l + r) / 2;
  if (l == r) return;
  if (val <= mid)
    update(ls[x], ls[y], l, mid, val);
  else
    update(rs[x], rs[y], mid + 1, r, val);
  return;
}
int query(int x, int y, int l, int r, int k) {
  if (sum[y] - sum[x] <= k) return N;
  int mid = (l + r) / 2;
  if (l == r) return l;
  int res = query(ls[x], ls[y], l, mid, k);
  if (res == N) res = query(rs[x], rs[y], mid + 1, r, k);
  return res;
}
int main() {
  int m;
  scanf("%d %d", &n, &m);
  int i, x;
  for (i = 1; i <= n; i++) {
    scanf("%d", &x);
    update(root[i], root[i - 1], 1, n, x);
  }
  while (m--) {
    int l, r, k;
    scanf("%d %d %d", &l, &r, &k);
    k = (r - l + 1) / k;
    int res = query(root[l - 1], root[r], 1, n, k);
    if (res == N) res = -1;
    printf("%d\n", res);
  }
  return 0;
}
