#include <bits/stdc++.h>
using namespace std;
ifstream fin("sequencequery.in");
ofstream fout("sequencequery.out");
const int NMAX=2e5+2;
int n, m;
struct Node{
long long sum;
long long prefmax;
long long sufmax;
long long smax;
int maxval;
} a[NMAX*4+1];
Node merge(Node L, Node R){
Node T;
T.maxval=max(L.maxval, R.maxval);
T.sum=L.sum+R.sum;
T.prefmax=max(L.prefmax, L.sum+R.prefmax);
T.sufmax=max(R.sufmax, R.sum+L.sufmax);
T.smax=max(max(L.smax, R.smax), L.sufmax+R.prefmax);
return T;
}
void update(int pos, int val, int node=1, int st=1, int dr=n){
if(st==dr){
a[node]={val, val, val, val, val};
return;
}
int mid=(st+dr)/2;
if(pos<=mid){
update(pos, val, node*2, st, mid);
}else{
update(pos, val, node*2+1, mid+1, dr);
}
a[node]=merge(a[node*2], a[node*2+1]);
}
Node query(int x, int y, int node=1, int st=1, int dr=n){
if(x>dr || y<st){
return {0, 0, 0, 0, INT_MIN};
}
if(x<=st && y>=dr){
return a[node];
}
int mid=(st+dr)/2;
if(mid>=y) return query(x, y, node*2, st, mid);
else if (mid<x) return query(x, y, node*2+1, mid+1, dr);
return merge(query(x, y, node*2, st, mid), query(x, y, node*2+1, mid+1, dr));
}
int main(){
fin >> n >> m;
for(int i=1; i<=n; i++){
int x;
fin >> x;
update(i, x);
}
while(m--){
int x, y;
fin >> x >> y;
Node ans=query(x, y);
//if(ans.smax==0) fout << ans.maxval << '\n';
fout << ans.smax << '\n';
}
}