/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <fstream>
using namespace std;
ifstream cin("rmq.in");
ofstream cout("rmq.out");
int rmq[20][100001];
int n,m;
int E[100001];
int st,dr;
int main()
{
cin>>n>>m;
for(int i=0;i<n;i++)
cin>>rmq[0][i];
for(int p=1;(1<<p)<n;p++)
for(int i=0;i<n;i++)
{
rmq[p][i]=rmq[p-1][i];
int j=i+(1<<(p-1));
if(j<n)
rmq[p][i]=min(rmq[p][i],rmq[p-1][j]);
}
E[1]=0;
for(int i=2;i<=n;i++)
E[i]=E[i/2]+1;
for(int i=0;i<m;i++)
{
cin>>st>>dr;
st--;
dr--;
int l=dr-st+1;
int p=(1<<E[l]);
cout<<min(rmq[E[l]][st],rmq[E[l]][dr-p+1])<<'\n';
}
return 0;
}