#include <fstream>
#define inf (long long)1e18
#define nmax (int)(1e5+1)
using namespace std;
ifstream cin("sequencequery.in");
ofstream cout("sequencequery.out");
int n,q,x,y;
long long v[nmax];
struct Aint{
long long s,st,dr,maxi;
}aint[4*nmax],sol;
void build(int nod,int st,int dr){
if(st==dr){
aint[nod]={v[st],v[st],v[st],v[st]};
return ;
}
int mid=(st+dr)/2;
build(2*nod,st,mid);
build(2*nod+1,mid+1,dr);
aint[nod].s=aint[2*nod].s+aint[2*nod+1].s;
aint[nod].st=max(aint[2*nod].s+aint[2*nod+1].st,aint[2*nod].st);
aint[nod].dr=max(aint[2*nod].dr+aint[2*nod+1].s,aint[2*nod+1].dr);
aint[nod].maxi=max(max(aint[2*nod].maxi,aint[2*nod+1].maxi),max(max(aint[nod].st,aint[nod].dr),aint[2*nod].dr+aint[2*nod+1].st));
}
void query(int nod,int st,int dr,int x,int y){
if(x<=st&&dr<=y){
if(sol.s==-inf)
sol=aint[nod];
else{
sol.maxi=max(sol.maxi,sol.dr+aint[nod].st);
sol.st=max(sol.st,sol.s+aint[nod].st);
sol.dr=max(aint[nod].dr,sol.dr+aint[nod].s);
sol.s+=aint[nod].s;
sol.maxi=max(max(max(sol.s,sol.maxi),aint[nod].maxi),max(sol.st,sol.dr));
}
return ;
}
int mid=(st+dr)/2;
if(x<=mid)
query(2*nod,st,mid,x,y);
if(mid<y)
query(2*nod+1,mid+1,dr,x,y);
}
int main()
{
cin>>n>>q;
for(int i=1;i<=n;i++)
cin>>v[i];
build(1,1,n);
while(q--){
cin>>x>>y;
sol={-inf,-inf,-inf,-inf};
query(1,1,n,x,y);
cout<<sol.maxi<<'\n';
}
return 0;
}