#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int N=100001;
int n,m;
int a[N],maxrmq[N][51];
inline int read()
{
int x=0;int f=1;char c=getchar();
while(c<‘0‘||c>‘9‘){if(c==‘-‘)f=-1;c=getchar();}
while(c>=‘0‘&&c<=‘9‘)x=x*10+c-‘0‘,c=getchar();
return x*f;
}
int rmqmax(int l,int r)
{
int k(0);
while(l+(1<<(k+1))<=r+1)k++;
return min(maxrmq[l][k],maxrmq[r-(1<<k)+1][k]);
}
int main()
{
n=read(),m=read();
for(int i=1;i<=n;i++)a[i]=read();
for(int i=1;i<=n;i++)maxrmq[i][0]=a[i];
for(int j=1;j<=25;j++)
for(int i=1;i+(1<<j)<=n + 1;i++)
maxrmq[i][j]=min(maxrmq[i][j-1],maxrmq[i+(1<<(j-1))][j-1]);
for(;m;m--)
{
int x=read(),y=read();
printf("%d ",rmqmax(x,y));
}
return 0;
}