#include <iostream>
#include <cmath>
using namespace std;
int maxN = 2e5+1;
int logN = 19;
int lookup[200001][19];
int main() {
int n,q;
cin>>n>>q;
int arr[n];
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
for(int i=0;i<n;i++)
{
lookup[i][0]=i;
}
for(int j=1;(1<<j)<=n;j++)
{
for(int i=0; (i+(1<<j)-1)<n;i++)
{
if(arr[lookup[i][j-1]] <= arr[lookup[i+(1<<(j-1))][j-1]])
{
lookup[i][j] = lookup[i][j-1];
}
else
{
lookup[i][j] = lookup[i+(1<<(j-1))][j-1];
}
}
}
/*for(int j=0;(1<<j)<=n;j++)
{
for(int i=0;i+(1<<j)-1 < n;i++)
{
cout<<lookup[i][j]<<" ";
}
cout<<endl;
}*/
for(int i=0;i<q;i++)
{
int a,b;
cin>>a>>b;
int j = log2(b-a+1);
cout<<min(arr[lookup[a-1][j]],arr[lookup[b-(1<<j)][j]])<<endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y21hdGg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWF4TiA9IDJlNSsxOwppbnQgbG9nTiA9IDE5OwoKaW50IGxvb2t1cFsyMDAwMDFdWzE5XTsKCmludCBtYWluKCkgewoJCglpbnQgbixxOwoJY2luPj5uPj5xOwoJCglpbnQgYXJyW25dOwoJZm9yKGludCBpPTA7aTxuO2krKykKCXsKCQljaW4+PmFycltpXTsKCX0KCQoJZm9yKGludCBpPTA7aTxuO2krKykKCXsKCQlsb29rdXBbaV1bMF09aTsKCX0KCQoJZm9yKGludCBqPTE7KDE8PGopPD1uO2orKykKCXsKCQlmb3IoaW50IGk9MDsgKGkrKDE8PGopLTEpPG47aSsrKQoJCXsKCQkJaWYoYXJyW2xvb2t1cFtpXVtqLTFdXSA8PSBhcnJbbG9va3VwW2krKDE8PChqLTEpKV1bai0xXV0pCgkJCXsKCQkJCWxvb2t1cFtpXVtqXSA9IGxvb2t1cFtpXVtqLTFd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