#include <bits/stdc++.h>
using namespace std;
using INT = long long;
const int NN = 303000;
int a[NN];
vector<int> buf[NN];
int cnt[NN];
int flag[NN];
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int calc(int id, int L, int R) {
  return upper_bound(buf[id].begin(), buf[id].end(), R) -
         lower_bound(buf[id].begin(), buf[id].end(), L);
}
int arr[NN];
int nn = 0;
int main() {
  int n, Q;
  cin >> n >> Q;
  srand(time(NULL));
  int N = 100000;
  vector<INT> RND;
  for (int i = 1; i <= N; i++) {
    RND.push_back(rng());
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    buf[a[i]].push_back(i);
  }
  int runs = 0;
  int pos = 0;
  while (Q--) {
    int L, R, k;
    scanf("%d %d %d", &L, &R, &k);
    int ans = -1;
    int mn = (R - L + 1) / k + 1;
    runs++;
    nn = 0;
    int step = 200;
    while (step--) {
      int id = a[RND[pos] % (R - L + 1) + L];
      pos++;
      if (pos == RND.size()) pos = 0;
      if (flag[id] == runs) {
        cnt[id]++;
        continue;
      }
      flag[id] = runs;
      arr[nn++] = id;
      cnt[id] = 1;
    }
    for (int i = 0; i < nn; i++)
      if (cnt[arr[i]] >= 200 / (k * 3)) {
        if (buf[arr[i]].size() < mn) continue;
        if (calc(arr[i], L, R) < mn) continue;
        if (ans == -1 || ans > arr[i]) ans = arr[i];
      }
    printf("%d\n", ans);
  }
}
