#include using namespace std; using ll = long long; template struct FenwickTree { // queries are right-exclusive; 0-based int n; vector tree; FenwickTree(int n) : n(n) { tree.assign(n + 1, 0); } T query(int l, int r) const { return query(r) - query(l); } // [l,r) T query(int r) const { // [0,r) T s = 0; for(; r > 0; r -= (r & (-r))) s += tree[r]; return s; } void update(int i, T v) { for(++i; i <= n; i += (i & (-i))) tree[i] += v; } }; ll test(int i, ll s, const FenwickTree &ft, const vector &a) { ll pre = ft.query(i); ll suf = s - a[i] - pre; if (a[i]&1) (pre <= suf ? pre : suf)++; return pre - suf; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, q; cin >> n >> q; vector a(n); FenwickTree ft(n + 1); for (int i = 0; i < n; ++i) { ll v; cin >> v; ft.update(i, a[i] = v); } while (q--) { int i; ll x; cin >> i >> x; ft.update(i, x - a[i]); a[i] = x; ll s = ft.query(0, n); int l = 0, r = n; while (l < r) { int m = (l + r) / 2; if (test(m, s, ft, a) < 0) l = m + 1; else r = m; } if (l > 0 && -test(l-1, s, ft, a) <= test(l, s, ft, a)) --l; cout << l << '\n'; } cout << flush; return 0; }