#include <cstdio>
#include <algorithm>
#define LL long long
#define NMAX 400007
using namespace std;
LL Ans, Sum, a[NMAX], b[NMAX], c[NMAX], d[NMAX];
void update(int Nod, int st, int dr, int Poz, int Val){
if(st == dr){
a[Nod] = b[Nod] = c[Nod] = d[Nod] = Val;
return;
}
int med = (st + dr) >> 1;
if(med >= Poz)
update(Nod * 2, st, med, Poz, Val);
else
update(Nod * 2 + 1, med + 1, dr, Poz, Val);
a[Nod] = max(a[Nod * 2], d[Nod * 2] + a[Nod * 2 + 1]);
b[Nod] = max(b[Nod * 2 + 1], b[Nod * 2] + d[Nod * 2 + 1]);
c[Nod] = max(max(c[Nod * 2], c[Nod * 2 + 1]), b[Nod * 2] + a[Nod * 2 + 1]);
d[Nod] = d[Nod * 2] + d[Nod * 2 + 1];
}
void query(int Nod, int st, int dr, int x, int y){
if(x <= st && dr <= y){
if(Sum < 0)
Sum = 0;
Ans = max(Ans, max(Sum + a[Nod], c[Nod]));
Sum = max(Sum + d[Nod], b[Nod]);
return;
}
int med = (st + dr) >> 1;
if(med >= x)
query(Nod * 2, st, med, x, y);
if(med < y)
query(Nod * 2 + 1, med + 1, dr, x, y);
}
int main(){
int n = 0, m = 0;
freopen("sequencequery.in", "r", stdin);
freopen("sequencequery.out", "w", stdout);
scanf("%d %d", &n, &m);
for(int i = 1; i <= n; ++i){
int a = 0;
scanf("%d", &a);
update(1, 1, n, i, a);
}
for(int i = 1; i <= m; ++i){
int x = 0, y = 0;
Ans = -100000000;
Sum = 0;
scanf("%d %d", &x, &y);
query(1, 1, n, x, y);
printf("%lld\n", Ans);
}
return 0;
}