#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 3e5 + 5;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int rand(int l, int r) {return uniform_int_distribution<int>(l, r)(rng);}
int n , q , S , ans;
ll a[MAXN] , cnt[MAXN] , res[MAXN];
int L = 1 , R = 0;
struct query{
int l , r , id , k;
} qu[MAXN];
void MO(int i)
{
while(L < qu[i].l){
cnt[a[L]]--;
L++;
}
while(L > qu[i].l){
L--;
cnt[a[L]]++;
}
while(R < qu[i].r){
R++;
cnt[a[R]]++;
}
while(R > qu[i].r){
cnt[a[R]]--;
R--;
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> q;
S = sqrt(n);
for(int i = 1 ; i <= n ; i++) cin >> a[i];
for(int i = 1 ; i <= q ; i++){
cin >> qu[i].l >> qu[i].r >> qu[i].k;
qu[i].id = i;
}
sort(qu + 1 , qu + 1 + q , [&] (query x, query y){
if (x.l / S == y.l) return x.r < y.r;
return x.l < y.l;
});
for(int i = 1 ; i <= q ; i++){
MO(i);
ll ans = 1e18;
for(int j = 1 ; j <= 100 ; j++){
int id = rand(qu[i].l , qu[i].r);
if(cnt[a[id]] > (qu[i].r - qu[i].l + 1) / qu[i].k)
ans = min(ans , a[id]);
}
res[qu[i].id] = ans;
}
for(int i = 1 ; i <= q ; i++)
cout << ((res[i] == 1e18) ? -1 : res[i]) << endl;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnR5cGVkZWYgbG9uZyBsb25nIGxsOwpjb25zdCBpbnQgTUFYTiA9IDNlNSArIDU7Cm10MTk5MzdfNjQgcm5nKGNocm9ubzo6aGlnaF9yZXNvbHV0aW9uX2Nsb2NrOjpub3coKS50aW1lX3NpbmNlX2Vwb2NoKCkuY291bnQoKSk7CgppbnQgcmFuZChpbnQgbCwgaW50IHIpIHtyZXR1cm4gdW5pZm9ybV9pbnRfZGlzdHJpYn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OyBpKyspewogICAgICAgIE1PKGkpOwogICAgICAgIGxsIGFucyA9IDFlMTg7CiAgICAgICAgZm9yKGludCBqID0gMSA7IGogPD0gMTAwIDsgaisrKXsKCiAgICAgICAgICAgIGludCBpZCA9IHJhbmQocXVbaV0ubCAsIHF1W2ldLnIpOwoKICAgICAgICAgICAgaWYoY250W2FbaWRdXSA+IChxdVtpXS5yIC0gcXVbaV0ubCArIDEpIC8gcXVbaV0uaykKICAgICAgICAgICAgICAgIGFucyA9IG1pbihhbnMgLCBhW2lkXSk7CiAgICAgICAgfQogICAgICAgIHJlc1txdVtpXS5pZF0gPSBhbnM7CiAgICB9CiAgICBmb3IoaW50IGkgPSAxIDsgaSA8PSBxIDsgaSsrKQogICAgICAgIGNvdXQgPDwgKChyZXNbaV0gPT0gMWUxOCkgPyAtMSA6IHJlc1tpXSkgPDwgZW5kbDsKfQ==