#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream fin("sequencequery.in");
ofstream fout("sequencequery.out");
const int nmax = 100000;
int n;
struct NODE
{
long long best = 0;
long long suf = 0;
long long pref = 0;
long long tot = 0;
} a[nmax * 4 + 5];
NODE best(NODE a,NODE b)
{
NODE c = {0,0,0,0};
c.pref = max(a.pref,a.tot + b.pref);
c.suf = max(b.suf,b.tot + a.suf);
c.best = max(c.pref,c.suf);
c.best = max(c.best, max(a.best,b.best));
c.best = max(c.best, a.suf + b.pref);
c.tot = a.tot+b.tot;
return c;
}
void build(int nod,int st,int dr)
{
if(st==dr)
{
int x;
fin>>x;
a[nod]= {x,x,x,x};
return;
}
int mid = (st+dr)/2;
build(nod*2,st,mid);
build(nod*2+1,mid+1,dr);
a[nod] = best(a[nod*2],a[nod*2+1]);
}
NODE query(int nod,int st,int dr,int x,int y)
{
if(x<=st && dr<=y)
return a[nod];
int mid = (st+dr)/2;
if(x<=mid && y>mid)
{
NODE a = query(nod*2,st,mid,x,y);
NODE b = query(nod*2+1,mid+1,dr,x,y);
return best(a,b);
}
if(x<=mid)
return query(nod*2,st,mid,x,y);
if(y>mid)
return query(nod*2+1,mid+1,dr,x,y);
}
int main()
{
int m;
fin>>n>>m;
build(1,1,n);
for(int i=1; i<=m; i++)
{
int x,y;
fin>>x>>y;
fout<<query(1,1,n,x,y).best<<'\n';
}
}