#include<iostream>
#include<cstring>
#include<algorithm>
#define END system("pause");
using namespace std;
const int maxn = 2e5 ;
int st[maxn][25];
int m, n;
void prework()
{
for (int j = 1; j < 23;j++)
{
for (int i = 1; i+(1<<j)-1 <= m;i++)
{
if(st[i][j - 1]<st[i + (1 << (j - 1))][j - 1])
st[i][j] =st[i][j - 1];
else
st[i][j]=st[i + (1 << (j - 1))][j - 1];
}
}
}
int query(int l,int r)
{
int s = log2(r - l + 1);
if(st[l][s]<st[r-(1<<s)+1][s])
return st[l][s];
else
return st[r-(1<<s)+1][s];
}
int main()
{
int l, r;
ios::sync_with_stdio(false);
cin >> m >> n;
for (int i = 1; i <= m;i++)
{
cin >> st[i][0];
}
prework();
while(n--)
{
cin >> l >> r;
cout<<query(l, r)<<endl;
}
END
}