#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
using namespace std;
using ll = long long;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
constexpr ll inf = 1LL<<60;

template<typename Monoid>
class SegmentTree{
private:
    using F = function<Monoid(Monoid&,Monoid&)>;
    int sz;
    vector<Monoid> seg;
    const F op;//演算
    const Monoid e;//単位元
public:
    SegmentTree(int n,const F op,const Monoid &e):op(op),e(e){
        sz = 1;
        while(sz<n) sz <<= 1;
        seg.assign(2*sz,e);
    }
    //代入
    void set(int k, const Monoid &x){
        seg[k+sz] = x;
    }
    //前計算(?)
    void build(){
        for(int i=sz-1;i>0;i--){
            seg[i] = op(seg[2*i],seg[2*i+1]);
        }
    }
    void update(int k,const Monoid &x){
        k += sz;
        seg[k] = x;
        while(k>>=1){
            seg[k] = op(seg[2*k],seg[2*k+1]);
        }
    }
    Monoid query(int l,int r){
        Monoid L = e,R = e;
        for(l+=sz,r+=sz;l<r;l>>=1,r>>=1){
            if(l&1) L = op(L,seg[l++]);
            if(r&1) R = op(seg[--r],R);
        }
        return op(L,R);
    }
    Monoid operator[](const int &k)const{
        return seg[k+sz];
    }
};

struct state{
    ll sum,lma,rma,ma;
};

state op(state& l,state& r){
    ll sum = 0,ma = -inf,lma = -inf,rma = -inf;
    sum = l.sum+r.sum;
    ma = max({l.ma,r.ma,l.rma+r.lma});
    lma = max(l.lma,l.sum+r.lma);
    rma = max(r.rma,r.sum+l.rma);
    return (state){sum,lma,rma,ma};
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,Q;
    cin >> N >> Q;
    SegmentTree<state> seg(N,op,(state){-inf,-inf,-inf});
    for(int i=0;i<N;i++){
        ll a;
        cin >> a;
        seg.set(i,(state){a,max(a,0LL),max(a,0LL),max(a,0LL)});
    }
    seg.build();
    cout << seg.query(0,N).ma << endl;
    for(int i=0;i<Q;i++){
        ll k,a;
        cin >> k >> a;
        k--;
        seg.update(k,(state){a,max(a,0LL),max(a,0LL),max(a,0LL)});
        cout << seg.query(0,N).ma << endl;
    }
}
