#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
using namespace std;
int n,m;
int a[10005],st[10005][20];
void ST(){
int k;
k=log(n)/log(2);
for(int i=1;i<=n;i++){
st[i][0]=a[i];
}
for(int i=1;i<=k;i++){
for(int j=1;j+(1<<i)-1<=n;j++){
st[i][j]=max(st[i][j-1],st[i+(1<<(j-1))][j-1]);
}
}
}
int rmq(int l,int r){
int k;
k=(r-l+1)/log(2);
return max(f[l][k],f[r-(1<<k)+1][k]);
}
int main(){
freopen("4.in","r",stdin);
freopen("4.out","w",stdout);
scanf("%d%d",&n,&m);
int l,r,ans;
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
}
ST();
for(int i=1;i<=n;i++){
scanf("%d%d",&l,&r);
ans=rmq(l,r);
printf("%d\n",ans);
}
return 0;
}