#include <bits/stdc++.h>
/*
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
*/
using namespace std;
const double eps = 1e-10;
const double pi = 3.1415926535897932384626433832795;
const double eln = 2.718281828459045235360287471352;
#define f(i, a, b) for (int i = a; i <= b; i++)
#define scan(x) scanf("%d", &x)
#define mp make_pair
#define pb push_back
#define lowbit(x) (x&(-x))
#define fi first
#define se second
#define SZ(x) int((x).size())
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define summ(a) (accumulate(all(a), 0ll))
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
using ll=long long;
const int maxn=2e5+9;
int n,m,rt[maxn],cnt,b[maxn],a[maxn],tot;
struct Node{
int l,r,val;
}tr[maxn*20];
inline void build(int &k,int l,int r){
k=++cnt;
if(l==r)return;
int mid=(l+r)>>1;
build(tr[k].l,l,mid),build(tr[k].r,mid+1,r);
}
inline void change(int &k,int kk,int l,int r,int val){
k=++cnt,tr[k]=tr[kk],tr[k].val+=1;
if(l==r)return ;
int mid=(l+r)>>1;
if(val<=mid)change(tr[k].l,tr[kk].l,l,mid,val);
else change(tr[k].r,tr[kk].r,mid+1,r,val);
}
inline int query(int nl,int nr,int l,int r,int k){
int x=tr[tr[nr].l].val-tr[tr[nl].l].val;
if(l==r)return b[l];
int mid=(l+r)>>1;
if(x>=k)return query(tr[nl].l,tr[nr].l,l,mid,k);
return query(tr[nl].r,tr[nr].r,mid+1,r,k-x);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m;
f(i,1,n)cin>>a[i],b[i]=a[i];
sort(b+1,b+1+n);
tot=unique(b+1,b+n+1)-(b+1);
build(rt[0],1,tot);
f(i,1,n){
int now=lower_bound(b+1,b+1+tot,a[i])-b;
change(rt[i],rt[i-1],1,tot,now);
}
for(int i=1,l,r,k;i<=m;++i){
cin>>l>>r>>k;
cout<<query(rt[l-1],rt[r],1,tot,k)<<"\n";
}
return 0;
}