#include <bits/stdc++.h>
using namespace std;

template <class T>
struct SegmentTree {
  // 1-indexed
  typedef function<T(T, T)> F;
  int n;
  F f;
  T unit;
  vector<T> dat;
  SegmentTree(){};
  SegmentTree(int newn, F f, T t) : f(f), unit(t) {
    init(newn);
  }
  void init(int newn) {
    n = 1;
    while(n < newn) n <<= 1;
    dat.assign(n << 1, unit);
  }

  // "go up" process
  void update(int k, T newdata) {
    dat[k += n] = newdata;
    while(k >>= 1) {
      dat[k] = f(dat[(k << 1)], dat[(k << 1) | 1]);
    }
  }
  // [a,b)
  T query(int a, int b) {
    T vl = unit, vr = unit;
    for(int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
      if(l & 1) vl = f(vl, dat[l++]);
      if(r & 1) vr = f(dat[--r], vr);
    }
    return f(vl, vr);
  }
};

struct data {
  long long all, lef, righ, ans;
  data(long long a, long long b, long long c, long long d)
      : all(a), lef(b), righ(c), ans(d) {}
};

long long n, q;
vector<long long> a;

int main() {
  auto f = [](data l, data r) {
    data now = l;
    now.all += r.all;
    now.lef = max(now.lef, l.all + r.lef);
    now.righ = max(r.righ, l.righ + r.all);
    now.ans = max({l.ans, r.ans, now.lef, now.righ, now.all,
                   l.righ + r.lef});
    return now;
  };
  cin >> n >> q;
  a.resize(n);
  for(int i = 0; i < n; ++i) cin >> a[i];
  SegmentTree<data> seg(n, f, data(0, 0, 0, 0));
  for(int i = 0; i < n; ++i)
    seg.update(i, {a[i], max(0LL, a[i]), max(0LL, a[i]),
                   max(0LL, a[i])});
  cout << seg.query(0, n).ans << endl;
  for(int i = 0; i < q; ++i) {
    long long k, x;
    cin >> k >> x;
    seg.update(k - 1,
               {x, max(0LL, x), max(0LL, x), max(0LL, x)});
    cout << seg.query(0, n).ans << endl;
  }
  return 0;
}
