#include<bits/stdc++.h>
#define MOD 1000000007
#define MODSET(d) if ((d) >= MOD) d %= MOD;
#define MODADDSET(d) if ((d) >= MOD) d -= MOD;
using namespace std;
#define MAXN 100000
#define LOGN 16
struct node
{
node *left, *right;
int value;
node(int v, node *l, node *r)
{
this->value = v;
this->left = l;
this->right = r;
}
node* insert(int l, int r, int index);
};
node* null;
node* node::insert(int l, int r, int index)
{
if (l <= index && index <= r)
{
if (l == r)
{
return new node(1, null, null);
}
else
{
int mid = (l + r)/2;
return new node(value+1, this->left->insert(l, mid, index), this->right->insert(mid+1, r, index));
}
}
else
{
return this;
}
}
node* root[MAXN+5];
int query(node* root, int l, int r, int k)
{
if (l == r)
{
return l;
}
int count = root->left->value;
int mid = (l + r)/2;
if (count >= k)
{
return query(root->left, l, mid, k);
}
else
{
return query(root->right, mid+1, r, k - count);
}
}
vector<int> positions[MAXN+5];
int arr[MAXN+5];
int main()
{
#ifdef VSP4
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n, q, i, j, d, L, K;
null = new node(0, NULL, NULL);
null->left = null->right = null;
scanf("%d %d", &n, &q);
for (i = 1; i <= n; i++)
{
scanf("%d", &d);
arr[i] = d;
positions[d].push_back(i);
}
root[MAXN+1] = null;
for (i = MAXN; i >= 1; i--)
{
root[i] = root[i+1];
if (!positions[i].empty())
{
for (auto p: positions[i])
{
root[i] = root[i]->insert(1, MAXN, p);
}
}
}
while (q--)
{
scanf("%d %d", &L, &K);
printf("%d\n", arr[query(root[L], 1, MAXN, K)]);
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KCiNkZWZpbmUgTU9EIDEwMDAwMDAwMDcKI2RlZmluZSBNT0RTRVQoZCkgaWYgKChkKSA+PSBNT0QpIGQgJT0gTU9EOwojZGVmaW5lIE1PREFERFNFVChkKSBpZiAoKGQpID49IE1PRCkgZCAtPSBNT0Q7Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKI2RlZmluZSBNQVhOID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