#include<bits/stdc++.h>
using namespace std;
const int M=4e5+4;
int n,q,a[M];
vector<int>tree[M],v;
#define all(v) v.begin(),v.end()
void build(int l,int r,int id)
{
if(l==r)
{
tree[id].push_back(a[l]);
return;
}
int m=(l+r)>>1;
build(l,m,2*id);
build(m+1,r,2*id+1);
merge(all(tree[2*id]),all(tree[2*id+1]),back_inserter(tree[id]));
}
int query(int l,int r,int id,int ql,int qr,int val)
{
if(r<ql || qr<l || ql>qr) return 0;
if(ql<=l && r<=qr)
return (int)(upper_bound(all(tree[id]),val)-tree[id].begin());
int m=(l+r)>>1;
return query(l,m,2*id,ql,qr,val)+query(m+1,r,2*id+1,ql,qr,val);
}
int main()
{
scanf("%d%d",&n,&q);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
v.push_back(a[i]);
}
sort(all(v));
for(int i=1;i<=n;i++) a[i]=lower_bound(all(v),a[i])-v.begin()+1;
build(1,n,1);
while(q--)
{
int l,r,k;
scanf("%d%d%d",&l,&r,&k);
int lo=1,hi=n,ans=-1;
while(lo<=hi)
{
int md=(lo+hi)>>1;
int vv=query(1,n,1,l,r,md);
if(k>vv) lo=md+1;
else if(k<vv) hi=md-1;
else
{
ans=md;
break;
}
}
if(ans!=1)
printf("%d\n",v[ans-1]);
else
printf("-1\n");
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKY29uc3QgaW50IE09NGU1KzQ7CmludCBuLHEsYVtNXTsKdmVjdG9yPGludD50cmVlW01dLHY7CiNkZWZpbmUgYWxsKHYpIHYuYmVnaW4oKSx2LmVuZCgpCnZvaWQgYnVpbGQoaW50IGwsaW50IHIsaW50IGlkKQp7CglpZihsPT1yKQoJewoJCXRyZWVbaWRdLnB1c2hfYmFjayhhW2xdKTsKCQlyZXR1cm47Cgl9CglpbnQgbT0obCtyKT4+MTsKCWJ1aWxkKGwsbSwyKmlkKTsKCWJ1aWxkKG0rMSxyLDIqaWQrMSk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