#include using namespace std; using T = long long; int main() { int n, q; cin >> n >> q; const int S = floor(sqrt(n)); // bucket size const int B = (n - 1) / S + 1; // number of buckets vector a(n), b(B); T sum = 0; for(int i = 0; i < n; ++i) { cin >> a[i]; sum += a[i]; b[i / S] += a[i]; } while(q--) { { int i; T x; cin >> i >> x; sum += x - a[i]; b[i / S] += x - a[i]; a[i] = x; assert(sum >= 0); } if(sum == 0) { cout << 0 << '\n'; continue; } int i = 0; T s = 0; while(2 * s <= sum) s += b[i++]; assert(i > 0); --i; pair best{numeric_limits::max(), -1}; int j = S * i - (i > 0), ls = s - b[i] - (i > 0 ? a[j] : 0); for(; j < min(S * (i + 1), n); ++j) { int rs = sum - ls - a[j]; best = min(best, {abs(abs(ls - rs)-a[j]%2), j}); ls += a[j]; } cout << best.second << '\n'; } return 0; }