import java.io.*;
public class Main{
static int N=100010,n,m;
static int w[]=new int[N];
static Node tr[]=new Node[N*4];
public static void main(String[] args)throws Exception {
BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));
String s1[]=sc.readLine().split(" ");
n=Integer.parseInt(s1[0]);
m=Integer.parseInt(s1[1]);
String s[]=sc.readLine().split(" ");
for(int i=1;i<=n;i++){
w[i]=Integer.parseInt(s[i-1]);
}
build(1,1,n);
while(m--!=0){
String s2[]=sc.readLine().split(" ");
int a=Integer.parseInt(s2[0]);
int b=Integer.parseInt(s2[1]);
bw.write(query(1,a,b)+"\n");
}
bw.flush();
sc.close();
bw.close();
}
static void pushup(int u){
tr[u].max=Math.max(tr[u<<1].max,tr[u<<1|1].max); //更新max
}
static void build(int u,int l,int r){ //初始化每个值
if(l==r) tr[u]=new Node(l,r,w[r]);
else{
tr[u]=new Node(l,r,0);
int mid=l+r>>1;
build(u<<1,l,mid); build(u<<1|1,mid+1,r);
pushup(u);
}
}
static int query(int u,int l,int r){ //查询区间和
if(l<=tr[u].l&&r>=tr[u].r) return tr[u].max;
else{
int mid=tr[u].l+tr[u].r>>1;
int res=Integer.MIN_VALUE;
if(l<=mid) res=query(u<<1,l,r);
if(r>mid) res=Math.max(res,query(u<<1|1,l,r));
return res;
}
}
static void modify(int u,int x,int v){ //修改操作
if(tr[u].l==tr[u].r) tr[u].max+=v;
else{
int mid=tr[u].l+tr[u].r>>1;
if(x<=mid) modify(u<<1,x,v);
else modify(u<<1|1,x,v);
pushup(u);
}
}
static class Node{ //节点
int l,r,max;
Node(int l,int r,int max){
this.l=l;
this.r=r;
this.max=max;
}
}
}