#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

template <typename T>
struct segment_tree {
    using F = function<T(T, T)>;
    int n;
    vector<T> data;
    F operation;
    T identity;
    segment_tree(F operation, T identity)
        : operation(operation), identity(identity) {}
    void init(int n_) {
        n = 1;
        while (n < n_) n <<= 1;
        data.assign(n<<1, identity);
    }
    void build(const vector<T> &v) {
        int n_ = (int)v.size();
        init(n_);
        for (int i = 0; i < n_; ++i) data[n+i] = v[i];
        for (int i = n-1; i >= 1; --i) {
            data[i] = operation(data[i<<1|0], data[i<<1|1]);
        }
    }
    T operator[](int i) { return data[n+i];}
    void set(int i, T x) {
        i += n;
        data[i] = x;
        while (i > 1) {
            i >>= 1;
            data[i] = operation(data[i<<1|0], data[i<<1|1]);
        }
    }
    T fold(int l, int r) {
        l += n; r += n;
        T resl = identity, resr = identity;
        while (l < r) {
            if (l & 1) resl = operation(resl, data[l++]);
            if (r & 1) resr = operation(data[--r], resr);
            l >>= 1; r >>= 1;
        }
        return operation(resl, resr);
    }
    template <typename C>
    int find(int st, C &check, T &acc, int i, int l, int r) {
        if (l+1 == r) {
            acc = operation(acc, data[i]);
            return check(acc) ? i-n : -1;
        }
        int m = (l+r)>>1;
        if (m <= st) return find(st, check, acc, i<<1|1, m, r);
        if (st <= l && !check(operation(acc, data[i]))) {
            acc = operation(acc, data[i]);
            return -1;
        }
        int vl = find(st, check, acc, i<<1|0, l, m);
        if (vl != -1) return vl;
        return find(st, check, acc, i<<1|1, m, r);
    }
    // min idx s.t. st <= idx && !check(fold(st, idx-1)) && check(fold(st, idx))
    template <typename C>
    int find(int st, C &check) {
        T acc = identity;
        return find(st, check, identity, 1, 0, n);
    }
};

struct max_subarray {
    ll sum, l, r, mx;
    max_subarray(ll sum=0, ll l=0, ll r=0, ll mx=0) : sum(sum), l(l), r(r), mx(mx) {}
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    auto f = [](max_subarray x, max_subarray y) {
                 max_subarray res;
                 res.sum = x.sum + y.sum;
                 res.l = max(x.l, x.sum + y.l);
                 res.r = max(y.r, x.r + y.sum);
                 res.mx = max({x.mx, y.mx, x.r + y.l});
                 return res;
             };
    max_subarray id;

    vector<max_subarray> b(n);
    rep(i, n) {
        ll relu = a[i] * (a[i] > 0);
        max_subarray val{a[i], relu, relu, relu};
        b[i] = val;
    }
    
    segment_tree<max_subarray> seg(f, id);
    seg.build(b);
    max_subarray res = seg.fold(0, n);
    cout << res.mx << endl;
    while (q--) {
        int k, x;
        cin >> k >> x;
        k--;
        ll relu = x * (x > 0);
        max_subarray val{x, relu, relu, relu};
        seg.set(k, val);
        max_subarray res = seg.fold(0, n);
        cout << res.mx << endl;
    }
}



Measured memory_bytes: 14452