#include <bits/stdc++.h>
#define ff first
#define ss second
#define oo 1000000007
using namespace std;
class wavelet{
int n, small, large;
vector<vector<int> > wt, l, r;
void build(int p, int L, int R, const vector<int>& v){
if(R <= L) return;
wt[p].assign(v.size()+1, 0);
l[p].assign(v.size()+1, 0);
r[p].assign(v.size()+1, 0);
int mid = (L+R)/2;
vector<int> left, right;
int c = 0;
for(int i = 0; i < v.size(); i++){
if(v[i] <= mid){
left.push_back(v[i]);
c++;
}
else{
right.push_back(v[i]);
}
l[p][i+1] = c, r[p][i+1] = i+1-c;
}
build(2*p, L, mid, left);
build(2*p+1, mid+1, R, right);
}
int find(int p, int L, int R, int i, int j, int k){
if(L == R) return L;
int mid = (L+R)/2;
int c = l[p][j] - l[p][i-1];
if(c >= k) return find(2*p, L, mid, l[p][i-1]+1, l[p][j], k);
else return find(2*p+1, mid+1, R, r[p][i-1]+1, r[p][j], k - c);
}
public:
wavelet(vector<int> &v) : n(v.size()), wt(4*v.size()), l(4*v.size()), r(4*v.size()){
small = oo;
large =-oo;
for(int i = 0; i < v.size(); i++)
small = min(small, v[i]),
large = max(large, v[i]);
build(1, small, large, v);
}
int find(int i, int j, int k){
return find(1, small, large, i, j, k);
}
};
int main(){
int n, m;
scanf("%d %d", &n, &m);
vector<int> v(n);
for(int i = 0; i < n; i++)
scanf("%d", &v[i]);
{
set<int> s;
for(int i = 0; i < n; i++) s.insert(v[i]);
map<int, int> go;
int ptr = 1;
for(int x : s) go[x] = ptr++;
for(int i = 0; i < n; i++) v[i] = go[ v[i] ];
}
wavelet wt(v);
for(int i = 0; i < m; i++){
int l, r, k;
scanf("%d %d %d", &l, &r, &k);
printf("%d\n", wt.find(l, r, k));
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CgojZGVmaW5lIGZmIGZpcnN0CiNkZWZpbmUgc3Mgc2Vjb25kCgojZGVmaW5lIG9vIDEwMDAwMDAwMDcKCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpjbGFzcyB3YXZlbGV0ewogICAgaW50IG4sIHNtYWxsLCBsYXJnZTsKICAgIHZlY3Rvcjx2ZWN0b3I8aW50PiA+IHd0LCBsLCByOwoKICAgIHZvaWQgYnVpbGQoaW50IHAsIGludCBMLCBpbnQgUiwgY29uc3QgdmVjdG9yPGludD4mIHYpewogICAgICAgIGlmKFIgPD0gTCkgcmV0dXJuOwogICAgICAgIHd0W3BdLmFzc2lnbih2LnNpemUoKSsxLCAwKTsKICAgICAgICBsW3BdLmFzc2lnbih2LnNpemUoKSsxLCAwKTsKICAgICAgICByW3BdLmFzc2lnbih2LnNpemUoKSsxLCAwKTsKICAgICAgICBpbnQgbWlkID0gKEwrUikvMjsKICAgICAgICB2ZWN0b3I8aW50PiBsZWZ0LCByaWdodDsKICAgICAgICBpbnQgYyA9IDA7CiAgICAgICAgZm9yKGludCBpID0gMDsgaSA8IHYuc2l6ZSgpOyBpKyspewogICAgICAgICAgICBpZih2W2ldIDw9IG1pZCl7CiAgICAgICAgICAgICAgICBsZWZ0LnB1c2hfYmFjayh2W2ldKTsKICAgICAgICAgICAgICAgIGMrKzsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlewogICAgICAgICAgICAgICAgcmlnaHQucHVzaF9iYWNrKHZbaV0pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGxbcF1baSsxXSA9IGMsIHJbcF1baSsxXSA9IGkrMS1jOwogICAgICAgIH0KICAgICAgICBidWlsZCgyKnAsIEwsIG1pZCwgbGVmdCk7CiAgICAgICAgYnVpbGQoMipwKzEsIG1pZCsxLCBSLCByaWdodCk7CiAgICB9CgogICAgaW50IGZpbmQoaW50IHAsIGludCBMLCBpbnQgUiwgaW50IGksIGludCBqLCBpbnQgayl7CiAgICAgICAgaWYoTCA9PSBSKSByZXR1cm4gTDsKICAgICAgICBpbnQgbWlkID0gKEwrUikvMjsKICAgICAgICBpbnQgYyA9IGxbcF1bal0gLSBsW3BdW2ktMV07CiAgICAgICAgaWYoYyA+PSBrKSByZXR1cm4gZmluZCgyKnAsIEwsIG1pZCwgbFtwXVtpLTFdKzEsIGxbcF1bal0sIGspOwogICAgICAgIGVsc2UgcmV0dXJuIGZpbmQoMipwKzEsIG1pZCsxLCBSLCByW3BdW2ktMV0rMSwgcltwXVtqXSwgayAtIGMpOwogICAgfQoKcHVibGljOgogICAgd2F2ZWxldCh2ZWN0b3I8aW50PiAmdikgOiBuKHYuc2l6ZSgpKSwgd3QoNCp2LnNpemUoKSksIGwoNCp2LnNpemUoKSksIHIoNCp2LnNpemUoKSl7CiAgICAgICAgc21hbGwgPSBvbzsKICAgICAgICBsYXJnZSA9LW9vOwogICAgICAgIGZvcihpbnQgaSA9IDA7IGkgPCB2LnNpemUoKTsgaSsrKQogICAgICAgICAgICBzbWFsbCA9IG1pbihzbWFsbCwgdltpXSksCiAgICAgICAgICAgIGxhcmdlID0gbWF4KGxhcmdlLCB2W2ldKTsKICAgICAgICBidWlsZCgxLCBzbWFsbCwgbGFyZ2UsIHYpOwogICAgfQogICAgCiAgICBpbnQgZmluZChpbnQgaSwgaW50IGosIGludCBrKXsKICAgICAgICByZXR1cm4gZmluZCgxLCBzbWFsbCwgbGFyZ2UsIGksIGosIGspOwogICAgfQp9OwoKaW50IG1haW4oKXsKCiAgICBpbnQgbiwgbTsKCiAgICBzY2FuZigiJWQgJWQiLCAmbiwgJm0pOwogICAgdmVjdG9yPGludD4gdihuKTsKCiAgICBmb3IoaW50IGkgPSAwOyBpIDwgbjsgaSsrKQogICAgICAgIHNjYW5mKCIlZCIsICZ2W2ldKTsKCiAgICB7CiAgICAgICAgc2V0PGludD4gczsKICAgICAgICBmb3IoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSBzLmluc2VydCh2W2ldKTsKICAgICAgICBtYXA8aW50LCBpbnQ+IGdvOwogICAgICAgIGludCBwdHIgPSAxOwogICAgICAgIGZvcihpbnQgeCA6IHMpIGdvW3hdID0gcHRyKys7CiAgICAgICAgZm9yKGludCBpID0gMDsgaSA8IG47IGkrKykgdltpXSA9IGdvWyB2W2ldIF07CiAgICB9CgogICAgd2F2ZWxldCB3dCh2KTsKCiAgICBmb3IoaW50IGkgPSAwOyBpIDwgbTsgaSsrKXsKICAgICAgICBpbnQgbCwgciwgazsKICAgICAgICBzY2FuZigiJWQgJWQgJWQiLCAmbCwgJnIsICZrKTsKICAgICAgICBwcmludGYoIiVkXG4iLCB3dC5maW5kKGwsIHIsIGspKTsKICAgIH0KCiAgICByZXR1cm4gMDsKfQo=