#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
const int MX = 222222;
int sum[MX<<2];
int n, q;
void push_up(int rt) {
sum[rt] = max(sum[rt<<1], sum[rt<<1|1]);
}
void Build(int l, int r, int rt) {
if (l == r) {
scanf("%d", &sum[rt]);
return ;
}
int m = (l + r)>>1;
Build(lson);
Build(rson);
push_up(rt);
}
void update(int pos, int add, int l, int r, int rt) {
if (l == r) {
sum[rt] = add;
return ;
}
int m = (l + r)>>1;
if (pos <= m) update(pos, add, lson);
else update(pos, add, rson);
push_up(rt);
}
int Query(int L, int R, int l, int r, int rt) {
if (L <= l && r <= R) {
return sum[rt];
}
int m = (l + r)>>1;
int Max = -INF;
if (L <= m) Max = max(Max, Query(L, R, lson));
if (R > m) Max = max(Max, Query(L, R, rson));
return Max;
}
int main() {
//freopen("input.txt", "r", stdin);
while (scanf("%d %d", &n, &q) != EOF) {
memset(sum, 0