#include <bits/stdc++.h>
using namespace std;
int n, q, vet[303030], ans[303030], l, r = -1, sq = sqrt(3e5), cnt[303030];
struct query {
  int l, r, id, b, v;
} que[303030];
bool comp(query& a, query& b) {
  if (a.b != b.b) return a.b < b.b;
  if (a.b & 1) return a.r > b.r;
  return a.r < b.r;
}
int bigrand() { return abs((rand() << 16) ^ rand()); }
int main() {
  srand(time(NULL));
  scanf("%d%d", &n, &q);
  for (int(i) = (0); (i) < (n); (i)++) scanf("%d", vet + i);
  for (int(i) = (0); (i) < (q); (i)++) {
    int k;
    scanf("%d%d%d", &que[i].l, &que[i].r, &k);
    que[i].l--, que[i].r--;
    que[i].id = i;
    que[i].b = que[i].l / sq;
    que[i].v = (que[i].r - que[i].l + 1) / k;
  }
  sort(que, que + q, comp);
  for (int(i) = (0); (i) < (q); (i)++) {
    int id = que[i].id, L = que[i].l, R = que[i].r, best = 1e9, v = que[i].v,
        t = R - L + 1;
    while (r < R) cnt[vet[++r]]++;
    while (r > R) cnt[vet[r--]]--;
    while (l > L) cnt[vet[--l]]++;
    while (l < L) cnt[vet[l++]]--;
    for (int(j) = (0); (j) < (80); (j)++) {
      int p = l + bigrand() % t;
      if (cnt[vet[p]] > v) best = min(best, vet[p]);
    }
    if (best > 1e8) best = -1;
    ans[id] = best;
  }
  for (int(i) = (0); (i) < (q); (i)++) printf("%d\n", ans[i]);
}
