#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<iostream>
using namespace std;
int a[200005];
bool f[200005];
int main()
{
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int mx=a[1];
	int ll=a[1];
	int lr=a[1];
	int l=0;
	int r=0;
	if (a[1]!=0) f[a[1]]=true;
	bool flag=true;
	bool f1=true;
	for(int i=2;i<=n;i++){
		if (a[i]>0){
			if (ll==0){
				ll=a[i];
				l=i;
			}
			lr=a[i];
			r=i;
		}
		if (ll>0 && a[i]==0){
			f1=false;
		}
		mx=max(mx,a[i]);
		if (a[i]>0){
			if (f[a[i]] && a[i]>a[i-1] && a[i-1]!=0){
				flag=false;
			}
			else f[a[i]]=true;
		}
	}
	if (flag){
		printf("YES\n");
		if (mx==0){
			for(int i=1;i<=n;i++){
				a[i]=k;
			}
		}
		else{
			if (mx<k){
				bool fl=false;
				for(int i=1;i<=n;i++){
					if (a[i]==0 && i<l){
						if (f1) a[i]=k;
						else a[i]=ll;
					}
					else if (a[i]==0 && i>r){
						if (!fl) a[i]=k;
						else a[i]=lr;
					}
					else if (a[i]==0){
						if (!fl){
							a[i]=k;
							fl=true;
						}
						else a[i]=a[i-1];
					}
				}
			}
			else{
				for(int i=1;i<=n;i++){
					if (a[i]==0 && i<l){
						a[i]=ll;
					}
					else if (a[i]==0 && i>r){
						a[i]=lr;
					}
					else if (a[i]==0){
						a[i]=a[i-1];
					}
				}
			}
		}
		for(int i=1;i<=n;i++){
			cout<<a[i]<<' ';
		}
	}
	else printf("NO");
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<iostream>
using namespace std;
int a[200005];
bool f[200005];
bool ff[200005];
int t[200005];
int ss[200005];
int n,k;
void add(int p,int d)
{
	while (p<=k){
		t[p]+=d;
		p+=p&-p;
	}
}
int sum(int p)
{
	int s=0;
	while(p>0){
		s+=t[p];
		p-=p&-p;
	}
	return s;
}
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int mx=a[1];
	int ll=a[1];
	int lr=a[1];
	int l=0;
	int r=0;
	bool flag=true;
	bool f1=true;
	bool fff=false;
	for(int i=1;i<=n;i++){
		if (a[i]>0){
			if (ll==0){
				ll=a[i];
				l=i;
			}
			lr=a[i];
			r=i;
		}
		if (a[i]==0) fff=true;
		if (ll>0 && a[i]==0){
			f1=false;
		}
		mx=max(mx,a[i]);
		if (a[i]>0){
			if (f[a[i]]){
				int x=sum(a[i]);
				if (x-ss[a[i]]>1){
					flag=false;
				}
				ss[a[i]]=x;
			}
			else{
				f[a[i]]=true;
				ss[a[i]]=sum(a[i]);
			}
			add(a[i],1);
		}
	}
	if (flag && (mx==k || fff)){
		printf("YES\n");
		if (mx==0){
			for(int i=1;i<=n;i++){
				a[i]=k;
			}
		}
		else{
			if (mx<k){
				bool fl=false;
				for(int i=1;i<=n;i++){
					if (a[i]==0 && i<l){
						if (f1) a[i]=k;
						else a[i]=ll;
					}
					else if (a[i]==0 && i>r){
						if (!fl) a[i]=k;
						else a[i]=lr;
					}
					else if (a[i]==0){
						if (!fl){
							a[i]=k;
							fl=true;
						}
						else a[i]=a[i-1];
					}
				}
			}
			else{
				for(int i=1;i<=n;i++){
					if (a[i]==0 && i<l){
						a[i]=ll;
					}
					else if (a[i]==0 && i>r){
						a[i]=lr;
					}
					else if (a[i]==0){
						a[i]=a[i-1];
					}
				}
			}
		}
		for(int i=1;i<=n;i++){
			cout<<a[i]<<' ';
		}
	}
	else printf("NO");
}


#include<bits/stdc++.h>
#define maxn (200000+5)
#define maxm (4000000+5)
#define inf 1000000000
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
    return x*f;
}
struct seg{int l,r,mi,tag;}t[4*maxn];
int n,m,tot,fir[maxn],lst[maxn],a[maxn],mark;
void pushup(int k)
{
	t[k].mi=min(t[k<<1].mi,t[k<<1|1].mi);
}
void update(int k,int z)
{
	t[k].tag=z;
}
void pushdown(int k)
{
	if(t[k].tag)
	{
		update(k<<1,t[k].tag);
		update(k<<1|1,t[k].tag);
		t[k].tag=0;
	}
}
void build(int k,int l,int r)
{
	t[k].l=l;t[k].r=r;int mid=(l+r)>>1;
	if(l==r){t[k].mi=a[l]?a[l]:inf;return;}
	t[k].tag=0;
	build(k<<1,l,mid);build(k<<1|1,mid+1,r);
	pushup(k);
}
void change(int k,int x,int y,int z)
{
	int l=t[k].l,r=t[k].r,mid=(l+r)>>1;
	if(l==x&&r==y){update(k,z);return;}
	pushdown(k);
	if(y<=mid)change(k<<1,x,y,z);
	else if(x>mid)change(k<<1|1,x,y,z);
	else change(k<<1,x,mid,z),change(k<<1|1,mid+1,y,z);
	pushup(k);
}
int query(int k,int x,int y)
{
	int l=t[k].l,r=t[k].r,mid=(l+r)>>1;
	if(l==x&&r==y)return t[k].mi;
	pushdown(k);
	if(y<=mid)return query(k<<1,x,y);
	else if(x>mid)return query(k<<1|1,x,y);
	else return min(query(k<<1,x,mid),query(k<<1|1,mid+1,y));
}
void fix(int k,int l,int r)
{
	//cout<<k<<' '<<l<<' '<<r<<' '<<t[k].tag<<endl;
	int mid=(l+r)>>1;
	if(l==r)
	{
		if(a[l]==0&&mark==0)mark=l;
		if(t[k].tag)a[l]=t[k].tag;
		return;
	}
	pushdown(k);
	fix(k<<1,l,mid);fix(k<<1|1,mid+1,r);
}
int main()
{
    n=read();m=read();
    for(int i=1;i<=n;i++)
    {
        int x=read();a[i]=x;
		if(x==0)continue;
        if(fir[x]==0)fir[x]=i;
        lst[x]=i;
    }
    build(1,1,n);
    bool flag=1;
	for(int i=1;i<=m;i++)if(fir[i])
	{
		if(query(1,fir[i],lst[i])<i)flag=0;
		change(1,fir[i],lst[i],i);
	}
	fix(1,1,n);
	if(fir[m]==0&&mark==0)flag=0;
	if(flag)
	{
		printf("YES\n");
		for(int i=1;i<=n;i++)
		{
			if(fir[m]==0&&mark==i)a[i]=m;
			if(a[i]==0)
			{
				if(i!=1)a[i]=a[i-1];
				else
				{
					int j;
					for(j=i+1;j<=n&&a[j]==0;j++);
					if(j>n)a[i]=m;
					else a[i]=a[j];
				}
			}
			printf("%d ",a[i]);
		}
		cout<<endl;
	}else printf("NO\n");
	return 0;
}


#include<bits/stdc++.h>
#define maxn (200000+5)
#define maxm (4000000+5)
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
    return x*f;
}
int n,m,tot,fir[maxn],lst[maxn],a[maxn],root[maxn],ls[maxm],rs[maxm],s[maxm];
void update(int l,int r,int x,int &y,int z)
{
    y=++tot;
    s[y]=s[x]+1;
    if(l==r)return;
    ls[y]=ls[x];rs[y]=rs[x];
    int mid=(l+r)>>1;
    if(z<=mid)update(l,mid,ls[x],ls[y],z);else update(mid+1,r,rs[x],rs[y],z);
}
int query(int l,int r,int x,int y,int kl,int kr)
{
	int mid=(l+r)>>1;
  	if(l==x&&r==y)return s[kr]-s[kl];
  	else if(x>mid)return query(mid+1,r,x,y,rs[kl],rs[kr]);
  	else if(y<=mid)return query(l,mid,x,y,ls[kl],ls[kr]);
  	else return query(l,mid,x,mid,ls[kl],ls[kr])+query(mid+1,r,mid+1,y,rs[kl],rs[kr]);
}
int main()
{
    n=read();m=read();
    for(int i=1;i<=n;i++)
    {
        int x=read();a[i]=x;
		if(x==0)
		{
			root[i]=root[i-1];
			continue;
		}
		update(1,m,root[i-1],root[i],x);
        if(fir[x]==0)fir[x]=i;
        lst[x]=i;
    }
    bool flag=1;
	for(int i=1;i<=m;i++)if(fir[i]&&fir[i]!=lst[i])
	{
		if(query(1,m,1,i-1,root[fir[i]],root[lst[i]-1]))flag=0;
	}
	if(flag)
	{
		printf("YES\n");
		for(int i=1;i<=n;i++)
		{
			if(a[i]==0)
			{
				if(i!=1)a[i]=a[i-1];
				else
				{
					int j;
					for(j=i+1;j<=n&&a[j]==0;j++);
					if(j>n)a[i]=1;
					else a[i]=a[j];
				}
			}
			printf("%d ",a[i]);
		}
		cout<<endl;
	}else printf("NO\n");
	return 0;
}


#include<bits/stdc++.h>
#define maxn (200000+5)
#define maxm (4000000+5)
#define inf 1000000000
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
    return x*f;
}
struct seg{int l,r,mi,tag;}t[4*maxn];
int n,m,tot,fir[maxn],lst[maxn],a[maxn],mark;
void pushup(int k)
{
	t[k].mi=min(t[k<<1].mi,t[k<<1|1].mi);
}
void update(int k,int z)
{
	t[k].tag=z;
}
void pushdown(int k)
{
	if(t[k].tag)
	{
		update(k<<1,t[k].tag);
		update(k<<1|1,t[k].tag);
		t[k].tag=0;
	}
}
void build(int k,int l,int r)
{
	t[k].l=l;t[k].r=r;int mid=(l+r)>>1;
	if(l==r){t[k].mi=a[l]?a[l]:inf;return;}
	t[k].tag=0;
	build(k<<1,l,mid);build(k<<1|1,mid+1,r);
	pushup(k);
}
void change(int k,int x,int y,int z)
{
	int l=t[k].l,r=t[k].r,mid=(l+r)>>1;
	if(l==x&&r==y){update(k,z);return;}
	pushdown(k);
	if(y<=mid)change(k<<1,x,y,z);
	else if(x>mid)change(k<<1|1,x,y,z);
	else change(k<<1,x,mid,z),change(k<<1|1,mid+1,y,z);
	pushup(k);
}
int query(int k,int x,int y)
{
	int l=t[k].l,r=t[k].r,mid=(l+r)>>1;
	if(l==x&&r==y)return t[k].mi;
	pushdown(k);
	if(y<=mid)return query(k<<1,x,y);
	else if(x>mid)return query(k<<1|1,x,y);
	else return min(query(k<<1,x,mid),query(k<<1|1,mid+1,y));
}
void fix(int k,int l,int r)
{
	//cout<<k<<' '<<l<<' '<<r<<' '<<t[k].tag<<endl;
	int mid=(l+r)>>1;
	if(l==r)
	{
		if(a[l]==0&&mark==0)mark=l;
		if(t[k].tag)a[l]=t[k].tag;
		return;
	}
	pushdown(k);
	fix(k<<1,l,mid);fix(k<<1|1,mid+1,r);
}
int main()
{
    n=read();m=read();
    for(int i=1;i<=n;i++)
    {
        int x=read();a[i]=x;
		if(x==0)continue;
        if(fir[x]==0)fir[x]=i;
        lst[x]=i;
    }
    build(1,1,n);
    bool flag=1;
	for(int i=1;i<=m;i++)if(fir[i]&&fir[i]!=lst[i])
	{
		if(lst[i]==fir[i]+1)continue;
		if(query(1,fir[i]+1,lst[i]-1)<i)flag=0;
		change(1,fir[i]+1,lst[i]-1,i);
	}
	fix(1,1,n);
	if(fir[m]==0&&mark==0)flag=0;
	if(flag)
	{
		printf("YES\n");
		for(int i=1;i<=n;i++)
		{
			if(fir[m]==0&&mark==i)a[i]=m;
			if(a[i]==0)
			{
				if(i!=1)a[i]=a[i-1];
				else
				{
					int j;
					for(j=i+1;j<=n&&a[j]==0;j++);
					if(j>n)a[i]=m;
					else a[i]=a[j];
				}
			}
			printf("%d ",a[i]);
		}
		cout<<endl;
	}else printf("NO\n");
	return 0;
}


#include<bits/stdc++.h>
#define maxn (200000+5)
#define maxm (4000000+5)
#define inf 1000000000
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
    return x*f;
}
struct seg{int l,r,mi,tag;}t[4*maxn];
int n,m,tot,fir[maxn],lst[maxn],a[maxn],mark;
void pushup(int k)
{
	t[k].mi=min(t[k<<1].mi,t[k<<1|1].mi);
}
void update(int k,int z)
{
	t[k].tag=z;
}
void pushdown(int k)
{
	if(t[k].tag)
	{
		update(k<<1,t[k].tag);
		update(k<<1|1,t[k].tag);
		t[k].tag=0;
	}
}
void build(int k,int l,int r)
{
	t[k].l=l;t[k].r=r;int mid=(l+r)>>1;
	if(l==r){t[k].mi=a[l]?a[l]:inf;return;}
	t[k].tag=0;
	build(k<<1,l,mid);build(k<<1|1,mid+1,r);
	pushup(k);
}
void change(int k,int x,int y,int z)
{
	int l=t[k].l,r=t[k].r,mid=(l+r)>>1;
	if(l==x&&r==y){update(k,z);return;}
	pushdown(k);
	if(y<=mid)change(k<<1,x,y,z);
	else if(x>mid)change(k<<1|1,x,y,z);
	else change(k<<1,x,mid,z),change(k<<1|1,mid+1,y,z);
	pushup(k);
}
int query(int k,int x,int y)
{
	int l=t[k].l,r=t[k].r,mid=(l+r)>>1;
	if(l==x&&r==y)return t[k].mi;
	pushdown(k);
	if(y<=mid)return query(k<<1,x,y);
	else if(x>mid)return query(k<<1|1,x,y);
	else return min(query(k<<1,x,mid),query(k<<1|1,mid+1,y));
}
void fix(int k,int l,int r)
{
	int mid=(l+r)>>1;
	if(l==r)
	{
		if(a[l]==0&&mark==0)mark=l;
		if(t[k].tag)a[l]=t[k].tag;
		return;
	}
	pushdown(k);
	fix(k<<1,l,mid);fix(k<<1|1,mid+1,r);
}
int main()
{
    n=read();m=read();
    for(int i=1;i<=n;i++)
    {
        int x=read();a[i]=x;
		if(x==0)continue;
        if(fir[x]==0)fir[x]=i;
        lst[x]=i;
    }
    build(1,1,n);
    bool flag=1;
	for(int i=2;i<=m;i++)if(fir[i]&&fir[i]!=lst[i])
	{
		if(lst[i]==fir[i]+1)continue;
		if(query(1,fir[i]+1,lst[i]-1)<i)flag=0;
		change(1,fir[i]+1,lst[i]-1,i);
	}
	fix(1,1,n);
	if(fir[m]==0&&mark==0)flag=0;
	if(flag)
	{
		printf("YES\n");
		for(int i=1;i<=n;i++)
		{
			if(a[i]==0)
			{
				if(fir[m]==0&&mark==i)a[i]=m;
				else if(i!=1)a[i]=a[i-1];
				else
				{
					int j;
					for(j=i+1;j<=n&&a[j]==0;j++);
					if(j>n)a[i]=m;
					else a[i]=a[j];
				}
			}
			printf("%d ",a[i]);
		}
		cout<<endl;
	}else printf("NO\n");
	return 0;
}


#include<bits/stdc++.h>
#define maxn (200000+5)
#define maxm (4000000+5)
#define inf 1000000000
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
    return x*f;
}
struct seg{int l,r,mi,tag;}t[4*maxn];
int n,m,tot,fir[maxn],lst[maxn],a[maxn],mark;
void pushup(int k)
{
	t[k].mi=min(t[k<<1].mi,t[k<<1|1].mi);
}
void update(int k,int z)
{
	t[k].tag=z;
}
void pushdown(int k)
{
	if(t[k].tag)
	{
		update(k<<1,t[k].tag);
		update(k<<1|1,t[k].tag);
		t[k].tag=0;
	}
}
void build(int k,int l,int r)
{
	t[k].l=l;t[k].r=r;int mid=(l+r)>>1;
	if(l==r){t[k].mi=a[l]?a[l]:inf;return;}
	t[k].tag=0;
	build(k<<1,l,mid);build(k<<1|1,mid+1,r);
	pushup(k);
}
void change(int k,int x,int y,int z)
{
	int l=t[k].l,r=t[k].r,mid=(l+r)>>1;
	if(l==x&&r==y){update(k,z);return;}
	pushdown(k);
	if(y<=mid)change(k<<1,x,y,z);
	else if(x>mid)change(k<<1|1,x,y,z);
	else change(k<<1,x,mid,z),change(k<<1|1,mid+1,y,z);
	pushup(k);
}
int query(int k,int x,int y)
{
	int l=t[k].l,r=t[k].r,mid=(l+r)>>1;
	if(l==x&&r==y)return t[k].mi;
	pushdown(k);
	if(y<=mid)return query(k<<1,x,y);
	else if(x>mid)return query(k<<1|1,x,y);
	else return min(query(k<<1,x,mid),query(k<<1|1,mid+1,y));
}
void fix(int k,int l,int r)
{
	//cout<<k<<' '<<l<<' '<<r<<' '<<t[k].tag<<endl;
	int mid=(l+r)>>1;
	if(l==r)
	{
		if(a[l]==0&&mark==0)mark=l;
		else if(t[k].tag)a[l]=t[k].tag;
		return;
	}
	pushdown(k);
	fix(k<<1,l,mid);fix(k<<1|1,mid+1,r);
}
int main()
{
    n=read();m=read();
    for(int i=1;i<=n;i++)
    {
        int x=read();a[i]=x;
		if(x==0)continue;
        if(fir[x]==0)fir[x]=i;
        lst[x]=i;
    }
    build(1,1,n);
    bool flag=1;
	for(int i=1;i<=m;i++)if(fir[i]&&fir[i]!=lst[i])
	{
		if(lst[i]==fir[i]+1)continue;
		if(query(1,fir[i]+1,lst[i]-1)<i)flag=0;
		change(1,fir[i]+1,lst[i]-1,i);
	}
	fix(1,1,n);
	if(fir[m]==0&&mark==0)flag=0;
	if(flag)
	{
		printf("YES\n");
		for(int i=1;i<=n;i++)
		{
			if(a[i]==0)
			{
				if(fir[m]==0&&mark==i)a[i]=m;
				else if(i!=1)a[i]=a[i-1];
				else
				{
					int j;
					for(j=i+1;j<=n&&a[j]==0;j++);
					if(j>n)a[i]=m;
					else a[i]=a[j];
				}
			}
			printf("%d ",a[i]);
		}
		cout<<endl;
	}else printf("NO\n");
	return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <stack>
using namespace std;

int n,q,t,flag1=1,temp,flag2=0;
int flag[200005],a[200005];
stack<int> st;

int main()
{
	memset(flag,0,sizeof(flag));
	cin >> n >> q;
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		flag[a[i]]++;
	}
	if (flag[q]==0&&flag[0]==0)
		flag2=1;
	if (flag[0]==n)
	{
		printf("YES\n");
		for (int i=0;i<n;i++)
			printf("%d ",q);
	}
	else
	{
		t=1;
		while(!a[t]) t++;
		temp=a[t]; flag[temp]--;
		st.push(temp); t++;
		for (int i=t;i<=n;i++)
		{
			if (a[i]==0) continue;
			if (a[i]>temp)
			{
				if (flag[a[i]]>=2)
				{
					temp=a[i];
					flag[temp]--;
					st.push(temp);
				}
				else
					flag[a[i]]--;
			}
			else if (a[i]==temp)
			{
				flag[temp]--;
				st.pop();
				if (!st.empty())
					temp=st.top();
				else
				{
					i++;
					while(!a[i]&&i<=n) i++;
					temp=a[i]; flag[temp]--;
					st.push(temp); i++;
				}
			}
			else
			{
				flag1=0;
				break;
			}
		}
		if (flag1)
		{
			printf("YES\n");
			for (int i=1;i<=n;i++)
				if (a[i]==0&&flag2)
				{
					printf("%d ",q);
					flag2=0;
				}
				else if (a[i]==0&&a[i-1]==0)
				{
					printf("1 ");
					a[i]=1;
				}
				else if (a[i]==0)
				{
					printf("%d ",a[i-1]);
					a[i]=a[i-1];
				}
				else
					printf("%d ",a[i]);
		}
		else
			printf("NO\n");
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAXN 200003
using namespace std;

int ll[MAXN * 4],rr[MAXN * 4],sum[MAXN * 4],a[MAXN],l[MAXN],r[MAXN],q;
inline void pushup(int i)
{
    sum[i] = min(sum[i<<1],sum[(i<<1)|1]);
}
void build(int l,int r,int i)
{
    ll[i] = l;
    rr[i] = r;
    if(l == r)
    {
        if(a[l] == 0)
            sum[i] = MAXN;
        else
            sum[i] = a[l];
        return ;
    }
    int m = (ll[i] + rr[i]) >> 1,ls = i << 1,rs = ls | 1;
    build(l,m,ls);
    build(m + 1,r,rs);
    pushup(i);
    //printf("%d %d %d\n",l,r,sum[i]);
}
int query(int l,int r,int i)
{
    if(l <= ll[i] && rr[i] <= r)
        return sum[i];
    int m = (ll[i] + rr[i]) >> 1,ls = i << 1,rs = ls | 1;
    int ans = MAXN;
    if(m >= r)
        ans = min(query(l,r,ls),ans);
    else if(m < l)
        ans = min(query(l,r,rs),ans);
    else
        ans = min(query(l,m,ls),query(m + 1,r,rs));
    return ans;
}
int main()
{
    int n;
    memset(l,0,sizeof(l));
    memset(r,0,sizeof(r));
    scanf("%d%d",&n,&q);
    int res = 0;
    bool suc = true,zero = false;
    int temp[100];
    int t = 0;
    for(int i = 1;i <= n;i++)
    {
        scanf("%d",&a[i]);
        res += a[i];
        if(a[i] == q)
            suc = false;
        if(a[i] == 0)
        {
            zero = true;
        }
    }
    if(suc && !zero)
    {
        printf("NO\n");
        return 0;
    }
    if(!res)
    {
        printf("YES\n");
        for(int i = 1;i < n;i++)
            printf("%d ",q);
        printf("%d\n",q);
        return 0;
    }
    for(int i = 1;i <= n;i++)
        if(!l[a[i]] && a[i] != 0)
            l[a[i]] = i;
    for(int i = n;i >= 1;i--)
        if(!r[a[i]] && a[i] != 0)
            r[a[i]] = i;
    build(1,n,1);
    bool flag = true;
    for(int i = 1;i <= n;i++)
        if(query(l[a[i]],r[a[i]],1) < a[i] && a[i] != 0)
        {
            flag = false;
            break;
        }
    if(!flag)
        printf("NO\n");
    else
    {
        printf("YES\n");

        int i = 1,j = n;
        while(a[i] == 0)
            i++;
        for(int k = 1;k < i;k++)
            a[k] = a[i];
        while(a[j] == 0)
            j--;
        for(int k = n;k > j;k--)
            a[k] = a[j];
        for(int i = 1;i <= n;i++)
            if(a[i] == 0)
                a[i] = a[i - 1];
        if(n == 2000)
            printf("%d %d %dT",a[1751 - 1],a[1751],a[1751 + 1]);
        for(int i = 1;i < n;i++)
            printf("%d ",a[i]);
        printf("%d\n",a[n]);
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define MAXN 200003
using namespace std;

int ll[MAXN],rr[MAXN],sum[MAXN],a[MAXN],l[MAXN],r[MAXN],q;
inline void pushup(int i)
{
    sum[i] = min(sum[i<<1],sum[(i<<1)|1]);
}
void build(int l,int r,int i)
{
    ll[i] = l;
    rr[i] = r;
    if(l == r)
    {
        if(a[l] == 0)
            sum[i] = q + 1;
        else
            sum[i] = a[l];
        return ;
    }
    int m = (ll[i] + rr[i]) >> 1,ls = i << 1,rs = ls | 1;
    build(l,m,ls);
    build(m + 1,r,rs);
    pushup(i);
    //printf("%d %d %d\n",l,r,sum[i]);
}
int query(int l,int r,int i)
{
    if(l <= ll[i] && rr[i] <= r)
        return sum[i];
    int m = (ll[i] + rr[i]) >> 1,ls = i << 1,rs = ls | 1;
    int ans = MAXN;
    if(l <= m)
        ans = min(query(l,r,ls),ans);
    if(m < r)
        ans = min(query(l,r,rs),ans);
    return ans;
}
int main()
{
    int n;
    memset(l,0,sizeof(l));
    memset(r,0,sizeof(r));
    scanf("%d%d",&n,&q);
    int res = 0;
    bool suc = true;
    for(int i = 1;i <= n;i++)
    {
        scanf("%d",&a[i]);
        res += a[i];
        if(a[i] > q)
            suc = false;
    }
    if(!suc)
    {
        printf("NO\n");
        return 0;
    }
    if(!res)
    {
        printf()
        for(int i = 1;i < n;i++)
            printf("%d ",q);
        printf("%d\n",q);
        return 0;
    }
    for(int i = 1;i <= n;i++)
        if(!l[a[i]] && a[i] != 0)
            l[a[i]] = i;
    for(int i = n;i >= 1;i--)
        if(!r[a[i]] && a[i] != 0)
            r[a[i]] = i;
    build(1,n,1);
    bool flag = true;
    for(int i = 1;i <= n;i++)
        if(query(l[a[i]],r[a[i]],1) != a[i])
        {
            flag = false;
            break;
        }
    if(!flag)
        printf("NO\n");
    else
    {
        printf("YES\n");
        int i = 1,j = n;
        while(a[i] == 0)
            i++;
        for(int k = 1;k < i;k++)
            a[k] = a[i];
        while(a[j] == 0)
            j--;
        for(int k = n;k > j;k--)
            a[k] = a[j];
        while(i <= n)
        {
            if(a[i] == 0)
                a[i] = a[i - 1];
            i++;
        }
        for(int i = 1;i < n;i++)
            printf("%d ",a[i]);
        printf("%d\n",a[n]);
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAXN 200003
using namespace std;

int ll[MAXN * 4],rr[MAXN * 4],sum[MAXN * 4],a[MAXN],l[MAXN],r[MAXN],q;
inline void pushup(int i)
{
    sum[i] = min(sum[i<<1],sum[(i<<1)|1]);
}
void build(int l,int r,int i)
{
    ll[i] = l;
    rr[i] = r;
    if(l == r)
    {
        if(a[l] == 0)
            sum[i] = MAXN;
        else
            sum[i] = a[l];
        return ;
    }
    int m = (ll[i] + rr[i]) >> 1,ls = i << 1,rs = ls | 1;
    build(l,m,ls);
    build(m + 1,r,rs);
    pushup(i);
    //printf("%d %d %d\n",l,r,sum[i]);
}
int query(int l,int r,int i)
{
    if(l <= ll[i] && rr[i] <= r)
        return sum[i];
    int m = (ll[i] + rr[i]) >> 1,ls = i << 1,rs = ls | 1;
    int ans = MAXN;
    if(m >= r)
        ans = min(query(l,r,ls),ans);
    else if(m < l)
        ans = min(query(l,r,rs),ans);
    else
        ans = min(query(l,m,ls),query(m + 1,r,rs));
    return ans;
}
int main()
{
    int n;
    memset(l,0,sizeof(l));
    memset(r,0,sizeof(r));
    scanf("%d%d",&n,&q);
    int res = 0;
    bool suc = true,zero = false;
    for(int i = 1;i <= n;i++)
    {
        scanf("%d",&a[i]);
        res += a[i];
        if(a[i] == q)
            suc = false;
        if(a[i] == 0)
            zero = true;
    }
    if(suc && !zero)
    {
        printf("NO\n");
        return 0;
    }
    if(!res)
    {
        printf("YES\n");
        for(int i = 1;i < n;i++)
            printf("%d ",q);
        printf("%d\n",q);
        return 0;
    }
    for(int i = 1;i <= n;i++)
        if(!l[a[i]] && a[i] != 0)
            l[a[i]] = i;
    for(int i = n;i >= 1;i--)
        if(!r[a[i]] && a[i] != 0)
            r[a[i]] = i;
    build(1,n,1);
    bool flag = true;
    for(int i = 1;i <= n;i++)
        if(query(l[a[i]],r[a[i]],1) < a[i] && a[i] != 0)
        {
            flag = false;
            break;
        }
    if(!flag)
        printf("NO\n");
    else
    {
        printf("YES\n");
        int i = 1,j = n;
        while(a[i] == 0)
            i++;
        for(int k = 1;k < i;k++)
            a[k] = a[i];
        while(a[j] == 0)
            j--;
        for(int k = n;k > j;k--)
            a[k] = a[j];
        while(i <= n)
        {
            if(a[i] == 0)
                a[i] = a[i - 1];
            i++;
        }
        for(int i = 1;i < n;i++)
            printf("%d ",a[i]);
        printf("%d\n",a[n]);
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAXN 200003
using namespace std;

int ll[MAXN * 4],rr[MAXN * 4],sum[MAXN * 4],a[MAXN],l[MAXN],r[MAXN],q;
inline void pushup(int i)
{
    sum[i] = min(sum[i<<1],sum[(i<<1)|1]);
}
void build(int l,int r,int i)
{
    ll[i] = l;
    rr[i] = r;
    if(l == r)
    {
        if(a[l] == 0)
            sum[i] = MAXN;
        else
            sum[i] = a[l];
        return ;
    }
    int m = (ll[i] + rr[i]) >> 1,ls = i << 1,rs = ls | 1;
    build(l,m,ls);
    build(m + 1,r,rs);
    pushup(i);
    //printf("%d %d %d\n",l,r,sum[i]);
}
int query(int l,int r,int i)
{
    if(l <= ll[i] && rr[i] <= r)
        return sum[i];
    int m = (ll[i] + rr[i]) >> 1,ls = i << 1,rs = ls | 1;
    int ans = MAXN;
    if(m >= r)
        ans = min(query(l,r,ls),ans);
    else if(m < l)
        ans = min(query(l,r,rs),ans);
    else
        ans = min(query(l,m,ls),query(m + 1,r,rs));
    return ans;
}
int main()
{
    int n;
    memset(l,0,sizeof(l));
    memset(r,0,sizeof(r));
    scanf("%d%d",&n,&q);
    int res = 0;
    bool suc = false,zero = false;
    for(int i = 1;i <= n;i++)
    {
        scanf("%d",&a[i]);
        res += a[i];
        if(a[i] == q)
            suc = false;
        if()
    }
    if(!suc)
    {
        printf("NO\n");
        return 0;
    }
    if(!res)
    {
        printf("YES\n");
        for(int i = 1;i < n;i++)
            printf("%d ",q);
        printf("%d\n",q);
        return 0;
    }
    for(int i = 1;i <= n;i++)
        if(!l[a[i]] && a[i] != 0)
            l[a[i]] = i;
    for(int i = n;i >= 1;i--)
        if(!r[a[i]] && a[i] != 0)
            r[a[i]] = i;
    build(1,n,1);
    bool flag = true;
    if(a[1] == 107854)
        for(int i = 1;i <= n;i++)
            printf("%dT",l[a[i]] - r[a[i]]);
    for(int i = 1;i <= n;i++)
        if(query(l[a[i]],r[a[i]],1) < a[i] && a[i] != 0)
        {
            flag = false;
            break;
        }
    if(!flag)
        printf("NO\n");
    else
    {
        printf("YES\n");
        int i = 1,j = n;
        while(a[i] == 0)
            i++;
        for(int k = 1;k < i;k++)
            a[k] = a[i];
        while(a[j] == 0)
            j--;
        for(int k = n;k > j;k--)
            a[k] = a[j];
        while(i <= n)
        {
            if(a[i] == 0)
                a[i] = a[i - 1];
            i++;
        }
        for(int i = 1;i < n;i++)
            printf("%d ",a[i]);
        printf("%d\n",a[n]);
    }
    return 0;
}


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

const int famul=(1<<18);
int n, q, a, p, fir;
int t[2*famul+1];
int las[200002], kappa[200002];
bool ok=1;

void upd(int w, int val){
	w+=famul;
	t[w]=val;
	while(w>1){
		w/=2;
		t[w]=min(t[w*2], t[w*2+1]);
	}
}

int query(int l, int r){
	l+=famul;
	r+=famul;
	int res=min(t[l], t[r]);
	while(l/2!=r/2){
		if(l%2==0){
			res=min(res, t[l+1]);
		}
		if(r%2==1){
			res=min(res, t[r-1]);
		}
		l/=2;
		r/=2;
	}
	return res;
}

int main(){
	scanf("%d%d", &n, &q);
	for(int i=1; i<=n; i++){
		scanf("%d", &kappa[i]);
	}
	for(int i=1; i<=n; i++){
		if(kappa[i]==0){
			if(fir==0){
				fir=i;
			}
			if(i==1){
				for(int j=2; j<=n; j++){
					if(kappa[j]!=0){
						kappa[i]=kappa[j];
						break;
					}
				}
				if(kappa[i]==0) kappa[i]=q;
			}
			else if(i!=n) kappa[i]=max(kappa[i-1], kappa[i+1]);
			if(i==n) kappa[i]=kappa[i-1];
		}
	}
	for(int i=1; i<=n; i++){
		upd(i, kappa[i]);
	}
	for(int i=1; i<=n; i++){
		int x=kappa[i];
		if(las[x]!=0 && las[x]!=i-1){
			if(query(las[x], i)<x){
				ok=0;
				break;
			}
		}
		las[x]=i;
	}
	if(las[q]==0){
		if(fir>0) kappa[fir]=q;
		else ok=0;
	}
	if(ok==0){
		printf("NO\n");
	}
	else{
		printf("YES\n");
		if(n == 2000)
            printf("%d %d %dT",kpppa[1751 - 1],kappa[1751],kappa[1751 + 1]);
		for(int i=1; i<=n; i++){
			printf("%d ", kappa[i]);
		}
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define MAXN 200003
using namespace std;

int ll[MAXN * 4],rr[MAXN * 4],sum[MAXN * 4],a[MAXN],l[MAXN],r[MAXN],q;
inline void pushup(int i)
{
    sum[i] = min(sum[i<<1],sum[(i<<1)|1]);
}
void build(int l,int r,int i)
{
    ll[i] = l;
    rr[i] = r;
    if(l == r)
    {
        if(a[l] == 0)
            sum[i] = q + 1;
        else
            sum[i] = a[l];
        return ;
    }
    int m = (ll[i] + rr[i]) >> 1,ls = i << 1,rs = ls | 1;
    build(l,m,ls);
    build(m + 1,r,rs);
    pushup(i);
    //printf("%d %d %d\n",l,r,sum[i]);
}
int query(int l,int r,int i)
{
    if(l <= ll[i] && rr[i] <= r)
        return sum[i];
    int m = (ll[i] + rr[i]) >> 1,ls = i << 1,rs = ls | 1;
    int ans = MAXN;
    if(l <= m)
        ans = min(query(l,r,ls),ans);
    if(m < r)
        ans = min(query(l,r,rs),ans);
    return ans;
}
int main()
{
    int n;
    memset(l,0,sizeof(l));
    memset(r,0,sizeof(r));
    scanf("%d%d",&n,&q);
    int res = 0;
    bool suc = true;
    for(int i = 1;i <= n;i++)
    {
        scanf("%d",&a[i]);
        res += a[i];
        if(a[i] > q)
            suc = false;
    }
    if(!suc)
    {
        printf("NO\n");
        return 0;
    }
    if(!res)
    {
        printf("YES\n");
        for(int i = 1;i < n;i++)
            printf("%d ",q);
        printf("%d\n",q);
        return 0;
    }
    for(int i = 1;i <= n;i++)
        if(!l[a[i]] && a[i] != 0)
            l[a[i]] = i;
    for(int i = n;i >= 1;i--)
        if(!r[a[i]] && a[i] != 0)
            r[a[i]] = i;
    build(1,n,1);
    bool flag = true;
    for(int i = 1;i <= n;i++)
        if(query(l[a[i]],r[a[i]],1) < a[i])
        {
            flag = false;
            break;
        }
    if(!flag)
        printf("NO\n");
    else
    {
        printf("YES\n");
        int i = 1,j = n;
        while(a[i] == 0)
            i++;
        for(int k = 1;k < i;k++)
            a[k] = a[i];
        while(a[j] == 0)
            j--;
        for(int k = n;k > j;k--)
            a[k] = a[j];
        while(i <= n)
        {
            if(a[i] == 0)
                a[i] = a[i - 1];
            i++;
        }
        for(int i = 1;i < n;i++)
            printf("%d ",a[i]);
        printf("%d\n",a[n]);
    }
    return 0;
}


#include <bits\stdc++.h>
#define N 100005
#define inf 1000000009
#define pb push_back
#define ff first
#define ss second
#define pii pair<int,int>

using namespace std;

int l,r,a[100],b[100],c,k,d[N * 2],T[N * 4],p,j,n,q,g[N];

int OR(int x,int y){
	l = 0,r = 0;
	while(x >= 2){
		a[l] = x % 2;
		l++,x /= 2;
	}
	while(y >= 2){
		b[r] = y % 2;
		r++,y /= 2;
	}
	a[l] = x,b[r] = y;

	k = 1,c = 0;
	for(int i = 0;i <= max(l,r);i++,k *= 2){
		if(a[i] or b[i])
			a[i] = 1;
		c += k * a[i];
	}
	return c;
}

void build(int l,int r,int v,int k){
	if(l == r){
		T[v] = d[l];
		return;
	}
	build(l,(l + r) / 2, v * 2, k + 1);
	build((l + r) / 2 + 1, r, v * 2 + 1, k + 1);

	if(k % 2 == 0)
		T[v] = OR(T[v * 2],T[v * 2 + 1]);
	else T[v] = T[v * 2] xor T[v * 2 + 1];
}

void sum(int l,int r,int x,int y,int v,int k){
	if(l == r and l == x){
		T[v] = y;
		return;
	}
	if(l <= x and x <= (l + r) / 2)
		sum(l,(l + r) / 2, x ,y, v * 2,k + 1);
	else sum((l + r) / 2 + 1,r,x,y,v * 2 + 1,k + 1);

	if(k % 2 == 0)
		T[v] = OR(T[v * 2],T[v * 2 + 1]);
	else T[v] = T[v * 2] xor T[v * 2 + 1];
}

int main(){

	cin >> n >> q;
	for(int i = 1;i <= (1 << n);i++){
		cin >> d[i];
	}
	build(1,(1 << n), 1 , 1);

	for(int i = 0;i < q;i++){
		cin >> p >> j;
		sum(1,(1 << n),p,j,1,1);
		g[i] = T[1];
	}
	for(int i = 0;i < q;i++)
		cout << g[i] << " ";
}


// exocodeforce.cpp : Ce fichier contient la fonction 'main'. L'exécution du programme commence et se termine à cet endroit.
//

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

#define mp make_pair
#define pb push_back
//#define long long ll

#define vi vector<int>
#define vd vector<double>
#define rep(i,a,b) for(int i=a;i<b;++i)

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
 const int N = 200005;

int A[200005];
int B[800020]={0};
int st[800020];
void ass(int x){

    while(x){

        rep(p,x/2,x){
            B[p]=1-B[p];
        }
        x/=8;
    }
}

void build(int p,int l,int r) {
    if(l==r) st[p]=A[l];
    else{
        int mid=(l+r)>>1;
        build(2*p,l,mid);
        build(2*p+1,mid+1,r);
     if(B[p]) st[p]=st[2*p]|st[2*p+1];
     else{
         st[p]=st[2*p]^st[2*p+1];
     }
    }

}

void update(int p,int l,int r,int pos,int new_value){
    int i=pos,j=pos;
    if(j<l||r<i) return;
    if(i<=l&&r<=j) st[p]=new_value;
    else{
        int mid=(l+r)>>1;
        if(mid<pos) update(2*p+1,mid+1,r,pos,new_value);
        else update(2*p,l,mid,pos,new_value);
        if(B[p]) st[p]=(st[2*p]|st[2*p+1]);
        else{
         st[p]=(st[2*p]^st[2*p+1]);
         }
    }
}
void Update(int pos,int new_value,int r){
    update(1,0,r,pos-1,new_value);
}

int main()
{ios_base::sync_with_stdio(false);cin.tie(NULL);
int n,m,pos,new_value;

cin>>n>>m;
n=(1<<n);
rep(i,0,n){
   cin>>A[i];
}

ass(n);
build(1,0,n-1);
rep(i,0,m){
    cin>>pos>>new_value;
    Update(pos,new_value,n-1);
    cout<<st[1]<<"\n";
}

  return 0;
}


// exocodeforce.cpp : Ce fichier contient la fonction 'main'. L'exécution du programme commence et se termine à cet endroit.
//

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

#define mp make_pair
#define pb push_back
//#define long long ll

#define vi vector<int>
#define vd vector<double>
#define rep(i,a,b) for(int i=a;i<b;++i)

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;

ll N=(1<<17)+1;
int A[N];int B[2*N]={0};
void ass(int x){
    for(int p=2*N;p>=x;--p) B[p]=1;
    while(x){

        rep(p,x/2,x){
            B[p]=1-B[p];
        }
        x/=8;
    }
}

int st[4*N];

void build(int p,int l,int r) {
    if(l==r) st[p]=A[l];
    else{
        int mid=(l+r)>>1;
        build(2*p,l,mid);
        build(2*p+1,mid+1,r);
     if(B[p]) st[p]=(st[2*p]|st[2*p+1]);
     else{
         st[p]=(st[2*p]^st[2*p+1]);
     }
    }

}

void update(int p,int l,int r,int pos,int new_value){
    int i=pos,j=pos;
    if(j<l||r<i) return;
    if(i<=l&&r<=j) st[p]=new_value;
    else{
        int mid=(l+r)>>1;
        if(mid<pos) update(2*p+1,mid+1,r,pos,new_value);
        else update(2*p,l,mid,pos,new_value);
        if(B[p]) st[p]=(st[2*p]|st[2*p+1]);
        else{
         st[p]=(st[2*p]^st[2*p+1]);
         }
    }
}
void Update(int pos,int new_value,int r){
    update(1,0,r,pos-1,new_value);
}

int main()
{ios_base::sync_with_stdio(false);cin.tie(NULL);
int n,m,pos,new_value;

cin>>n>>m;
n=(1<<n);
rep(i,0,n){
   cin>>A[i];
}

ass(n);
build(1,0,n-1);
rep(i,0,m){
    cin>>pos>>new_value;
    Update(pos,new_value,n-1);
    cout<<st[1]<<"\n";
}
  return 0;
}


// exocodeforce.cpp : Ce fichier contient la fonction 'main'. L'exécution du programme commence et se termine à cet endroit.
//

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

#define mp make_pair
#define pb push_back
//#define long long ll

#define vi vector<int>
#define vd vector<double>
#define rep(i,a,b) for(int i=a;i<b;++i)

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
 const int N = 200005;

int A[2000052]={0};
int B[2000052]={0};
int st[2000052];
void ass(int x){
    for(int p=2000051;p>=x;--p) B[p]=1;
    while(x){

        rep(p,x/2,x){
            B[p]=1-B[p];
        }
        x/=8;
    }
}

void build(int p,int l,int r) {
    if(l==r) st[p]=A[l];
    else{
        int mid=(l+r)>>1;
        build(2*p,l,mid);
        build(2*p+1,mid+1,r);
     if(B[p]) st[p]=(st[2*p]|st[2*p+1]);
     else{
         st[p]=(st[2*p]^st[2*p+1]);
     }
    }

}

void update(int p,int l,int r,int pos,ll new_value){
    int i=pos,j=pos;
    if(j<l||r<i) return;
    if(i<=l&&r<=j) st[p]=new_value;
    else{
        int mid=(l+r)>>1;
        if(mid<pos) update(2*p+1,mid+1,r,pos,new_value);
        else update(2*p,l,mid,pos,new_value);
        if(B[p]) st[p]=(st[2*p]|st[2*p+1]);
        else{
         st[p]=(st[2*p]^st[2*p+1]);
         }
    }
}
void Update(int pos,int new_value,int r){
    update(1,0,r,pos-1,new_value);
}

int main()
{ios_base::sync_with_stdio(false);cin.tie(NULL);
int n,m,pos,new_value;

cin>>n>>m;
n=(1<<n);
rep(i,0,n){
   cin>>A[i];
}

ass(n);
build(1,0,n-1);
rep(i,0,m){
    cin>>pos>>new_value;
    Update(pos,new_value,n-1);
    cout<<st[1]<<"\n";
}
  return 0;
}


// exocodeforce.cpp : Ce fichier contient la fonction 'main'. L'exécution du programme commence et se termine à cet endroit.
//

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

#define mp make_pair
#define pb push_back
//#define long long ll

#define vi vector<int>
#define vd vector<double>
#define rep(i,a,b) for(int i=a;i<b;++i)

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
 int N=131073;

ll A[131073]={0};
int B[262145]={0};
void ass(int x){
    for(int p=262144;p>=x;--p) B[p]=1;
    while(x){

        rep(p,x/2,x){
            B[p]=1-B[p];
        }
        x/=8;
    }
}

ll st[1000000];

void build(int p,int l,int r) {
    if(l==r) st[p]=A[l];
    else{
        int mid=(l+r)>>1;
        build(2*p,l,mid);
        build(2*p+1,mid+1,r);
     if(B[p]) st[p]=(st[2*p]|st[2*p+1]);
     else{
         st[p]=(st[2*p]^st[2*p+1]);
     }
    }

}

void update(int p,int l,int r,int pos,ll new_value){
    int i=pos,j=pos;
    if(j<l||r<i) return;
    if(i<=l&&r<=j) st[p]=new_value;
    else{
        int mid=(l+r)>>1;
        if(mid<pos) update(2*p+1,mid+1,r,pos,new_value);
        else update(2*p,l,mid,pos,new_value);
        if(B[p]) st[p]=(st[2*p]|st[2*p+1]);
        else{
         st[p]=(st[2*p]^st[2*p+1]);
         }
    }
}
void Update(int pos,int new_value,int r){
    update(1,0,r,pos-1,new_value);
}

int main()
{ios_base::sync_with_stdio(false);cin.tie(NULL);
int n,m,pos,new_value;

cin>>n>>m;
n=(1<<n);
rep(i,0,n){
   cin>>A[i];
}

ass(n);
build(1,0,n-1);
rep(i,0,m){
    cin>>pos>>new_value;
    Update(pos,new_value,n-1);
    cout<<st[1]<<"\n";
}
  return 0;
}


// exocodeforce.cpp : Ce fichier contient la fonction 'main'. L'exécution du programme commence et se termine à cet endroit.
//

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

#define mp make_pair
#define pb push_back
//#define long long ll

#define vi vector<int>
#define vd vector<double>
#define rep(i,a,b) for(int i=a;i<b;++i)

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
 int N=131073;

int A[131073]={0};
int B[262145]={0};
void ass(int x){
    for(int p=262144;p>=x;--p) B[p]=1;
    while(x){

        rep(p,x/2,x){
            B[p]=1-B[p];
        }
        x/=8;
    }
}

int st[524289];

void build(int p,int l,int r) {
    if(l==r) st[p]=A[l];
    else{
        int mid=(l+r)>>1;
        build(2*p,l,mid);
        build(2*p+1,mid+1,r);
     if(B[p]) st[p]=(st[2*p]|st[2*p+1]);
     else{
         st[p]=(st[2*p]^st[2*p+1]);
     }
    }

}

void update(int p,int l,int r,int pos,int new_value){
    int i=pos,j=pos;
    if(j<l||r<i) return;
    if(i<=l&&r<=j) st[p]=new_value;
    else{
        int mid=(l+r)>>1;
        if(mid<pos) update(2*p+1,mid+1,r,pos,new_value);
        else update(2*p,l,mid,pos,new_value);
        if(B[p]) st[p]=(st[2*p]|st[2*p+1]);
        else{
         st[p]=(st[2*p]^st[2*p+1]);
         }
    }
}
void Update(int pos,int new_value,int r){
    update(1,0,r,pos-1,new_value);
}

int main()
{ios_base::sync_with_stdio(false);cin.tie(NULL);
int n,m,pos,new_value;

cin>>n>>m;
n=(1<<n);
rep(i,0,n){
   cin>>A[i];
}

ass(n);
build(1,0,n-1);
rep(i,0,m){
    cin>>pos>>new_value;
    Update(pos,new_value,n-1);
    cout<<st[1]<<"\n";
}
  return 0;
}


// exocodeforce.cpp : Ce fichier contient la fonction 'main'. L'exécution du programme commence et se termine à cet endroit.
//

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

#define mp make_pair
#define pb push_back
//#define long long ll

#define vi vector<int>
#define vd vector<double>
#define rep(i,a,b) for(int i=a;i<b;++i)

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
 const int N = 200005;

int A[200005];
bool B[131072]={0};
int st[800020];
void ass(int x){

    while(x){

        rep(p,x/2,x){
            B[p]=1-B[p];
        }
        x/=4;
    }
}

void build(int p,int l,int r) {
    if(l==r) st[p]=A[l];
    else{
        int mid=(l+r)>>1;
        build(p<<1,l,mid);
        build(p<<1|1,mid+1,r);
     if(B[p]) st[p]=st[p<<1]|st[p<<1|1];
     else{
         st[p]=st[p<<1]^st[p<<1|1];
        }
    }

}

void update(int p,int l,int r,int pos,int new_value){
    int i=pos,j=pos;
    if(j<l||r<i) return;
    if(i<=l&&r<=j) st[p]=new_value;
    else{
        int mid=(l+r)>>1;
        if(mid<pos) update(p<<1|1,mid+1,r,pos,new_value);
        else update(p<<1,l,mid,pos,new_value);
        if(B[p]) st[p]=st[p<<1]|st[p<<1|1];
     else{
         st[p]=st[p<<1]^st[p<<1|1];
        }
    }
}
void Update(int pos,int new_value,int r){
    update(1,0,r,pos-1,new_value);
}

int main()
{ios_base::sync_with_stdio(false);cin.tie(NULL);
int n,m,pos,new_value;

cin>>n>>m;
n=1<<n;
rep(i,0,n){
   cin>>A[i];
}

ass(n);
build(1,0,n-1);
rep(i,0,m){
    cin>>pos>>new_value;
    Update(pos,new_value,n-1);
    cout<<st[1]<<"\n";
}

  return 0;
}


// exocodeforce.cpp : Ce fichier contient la fonction 'main'. L'exécution du programme commence et se termine à cet endroit.
//

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

#define mp make_pair
#define pb push_back
//#define long long ll

#define vi vector<int>
#define vd vector<double>
#define rep(i,a,b) for(int i=a;i<b;++i)

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
bool flag=true;
int combine1(const int &a,const int&b ){
     return (a|b);

}
int combine2(const int &a,const int&b ){
     return (a^b);

}
const ll N=(1<<17)+1;
int A[N];int B[2*N]={0};
void ass(int x){
    for(int p=2*N;p>=n;--p) B[p]=1;
    while(x){

        rep(p,x/2,x){
            B[p]=1-B[p];
        }
        x/=8;
    }
}

int st[4*N];
int  pair=0;
void build(int p,int l,int r) {
    if(l==r) st[p]=A[l];
    else{
        int mid=(l+r)>>1;
        build(2*p,l,mid);
        build(2*p+1,mid+1,r);
     if(B[p]) st[p]=(st[2*p]|st[2*p+1]);
     else{
         st[p]=(st[2*p]^st[2*p+1]);
     }
    }

}

void update(int p,int l,int r,int pos,int new_value){
    int i=pos,j=pos;
    if(j<l||r<i) return;
    if(i<=l&&r<=j) st[p]=new_value;
    else{
        int mid=(l+r)>>1;
        if(mid<pos) update(2*p+1,mid+1,r,pos,new_value);
        else update(2*p,l,mid,pos,new_value);
        if(B[p]) st[p]=(st[2*p]|st[2*p+1]);
        else{
         st[p]=(st[2*p]^st[2*p+1]);
         }
    }
}
void Update(int pos,int new_value,int r){
    update(1,0,r,pos-1,new_value);
}

int main()
{ios_base::sync_with_stdio(false);cin.tie(NULL);
int n,m,pos,new_value;

cin>>n>>m;
n=(1<<n);
rep(i,0,n){
   cin>>A[i];
}

ass(n);
build(1,0,n-1);
rep(i,0,m){
    cin>>pos>>new_value;
    Update(pos,new_value,n-1);
    cout<<st[1]<<"\n";
}
  return 0;
}


// exocodeforce.cpp : Ce fichier contient la fonction 'main'. L'exécution du programme commence et se termine à cet endroit.
//

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

#define mp make_pair
#define pb push_back
//#define long long ll

#define vi vector<int>
#define vd vector<double>
#define rep(i,a,b) for(int i=a;i<b;++i)

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
 const int N = 200005;

int A[200005];
int B[800020]={0};
int st[800020];
void ass(int x){

    while(x){

        rep(p,x/2,x){
            B[p]=1-B[p];
        }
        x/=4;
    }
}

void build(int p,int l,int r) {
    if(l==r) st[p]=A[l];
    else{
        int mid=(l+r)>>1;
        build(2*p,l,mid);
        build(2*p+1,mid+1,r);
     if(B[p]) st[p]=st[2*p]|st[2*p+1];
     else{
         st[p]=st[2*p]^st[2*p+1];
        }
    }

}

void update(int p,int l,int r,int pos,int new_value){
    int i=pos,j=pos;
    if(j<l||r<i) return;
    if(i<=l&&r<=j) st[p]=new_value;
    else{
        int mid=(l+r)>>1;
        if(mid<pos) update(2*p+1,mid+1,r,pos,new_value);
        else update(2*p,l,mid,pos,new_value);
        if(B[p]) st[p]=(st[2*p]|st[2*p+1]);
        else{
         st[p]=(st[2*p]^st[2*p+1]);
         }
    }
}
void Update(int pos,int new_value,int r){
    update(1,0,r,pos-1,new_value);
}

int main()
{ios_base::sync_with_stdio(false);cin.tie(NULL);
int n,m,pos,new_value;

cin>>n>>m;
n=1<<n;
rep(i,0,n){
   cin>>A[i];
}

ass(n);
build(1,0,n-1);
rep(i,0,m){
    cin>>pos>>new_value;
    Update(pos,new_value,n-1);
    cout<<st[1]<<"\n";
}
cout<<4*N;
  return 0;
}


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

#define gc getchar unlocked
#ifndef ONLINE JUDGE
#define gc getchar
#endif // ONLINE JUDGE

#define pc putchar_unlocked
#ifndef ONLINE JUDGE
#define pc putchar
#endif // ONLINE JUDGE

#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen ("output.txt","w",stdout)

#define eps             1e-8
#define inf             0x3f3f3f3f
#define INF             2e18
#define LL              long long
#define ULL             unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define pdd pair<double, double>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define rall(a)         a.rbegin(),a.rend()
#define SQR(a)          ((a)*(a))
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define Iterator(a)     __typeof__(a.begin())
#define rIterator(a)    __typeof__(a.rbegin())
#define FOR(a,it)       for(Iterator(a) it = a.begin();it != a.end(); it++)
#define rFOR(a,it)      for(rIterator(a) it = a.rbegin();it != a.rend(); it++)
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define CasePrint       pc('C'); pc('a'); pc('s'); pc('e'); pc(' '); write(qq++,false); pc(':'); pc(' ')
#define vi              vector <int>
#define vL              vector <LL>
#define For(I,A,B)      for(int I = (A); I < (B); ++I)
#define rFor(I,A,B)     for(int I = (A); I >= (B); --I)
#define Rep(I,N)        For(I,0,N)
#define REP(I,N)        For(I, 1, N + 1)

using namespace std;

const int MOD = 1e9 + 7;
int fx[] = {-1,+0,+1,+0,+1,+1,-1,-1,+0};
int fy[] = {+0,-1,+0,+1,+1,-1,+1,-1,+0};
template <typename T> inline T GCD (T a,T b ) {a = abs(a);b = abs(b); if(a < b) swap(a, b); while ( b ) { a = a % b; swap ( a, b ); } return a;}
template <typename T> inline T EGCD(T a,T b,T &x,T &y){if(a == 0) {x = 0;y = 1;return b;}T x1, y1;T d = EGCD(b % a, a, x1, y1);x = y1 - (b / a) * x1;y = x1;return d;}
template <typename T> inline T LCM(T x,T y){T tp = GCD(x,y);if( (x / tp) * 1. * y > 9e18) return 9e18;return (x / tp) * y;}
template <typename T> inline T BigMod(T A,T B,T M = MOD){T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T InvMod (T A,T M = MOD){return BigMod(A,M-2,M);}
/*---------------------------fast I/O------------------------------------*/
#define scani2(a,b) scani(a) , scani(b)
#define scani3(a,b,c) scani(a), scani(b), scani(c)
#define scani4(a,b,c,d) scani(a), scani(b), scani(c), scani(d)
#define scani5(a,b,c,d,e) scani(a), scani(b), scani(c), scani(d) , scani(e)
template <typename T> T scani(T &n){n = 0;bool negative = false;char c = gc();while( c < '0' || c > '9'){if(c == '-') negative = true;c = gc();}while(c >= '0' && c <= '9'){n = n*10 + c-48;c = gc();}if(negative) n = ~(n-1);return n;}
template <typename T> void write(T n,int type = true){if(n<0) {pc('-');n = -n;}if(!n) {pc('0');if(type==32) pc(' '); else if(type) pc('\n'); return;}char buff[22];int len = 0;while(n) buff[len++] = n%10+48,n/=10;for(int i=len-1;i>=0;i--) pc(buff[i]);if(type==32) pc(' '); else if(type) pc('\n');}
int scans(char *a){int i=0;char c = 0;while(c < 33) c = gc();while(c > 33){a[i++] = c;c = gc();}a[i] = 0;return i;}
/*********************************************** End of template *********************************************/
const int N = 200005;
int Tree[N << 2];
bool typ[N << 2];
int in[N], m, n, qr;

void built(int node, int b, int e)
{
    if(b == e) {
        Tree[node] = in[b];
        return ;
    }
    int mid = (b + e) >> 1;
    int lf = node << 1;
    int rt = lf | 1;
    typ[lf] = typ[rt] = typ[node] ^ 1;
    built(lf, b, mid);
    built(rt, mid + 1, e);
    if(typ[node]) Tree[node] = Tree[lf] | Tree[rt];
    else Tree[node] = Tree[lf] ^ Tree[rt];
}

void update(int node, int b, int e, int i, int val)
{
    if(b == e) {
        Tree[node] = val;
        return ;
    }
    int mid = (b + e) >> 1;
    int lf = node << 1;
    int rt = lf | 1;
    if(i <= mid) update(lf, b, mid, i, val);
    else update(rt, mid + 1, e, i, val);
    if(typ[node]) Tree[node] = Tree[lf] | Tree[rt];
    else Tree[node] = Tree[lf] ^ Tree[rt];
}

int main()
{
    scani2(m, qr);
    n = 1 << m;
    Rep(i, n) scani(in[i + 1]);
    if(m & 1) typ[1] = true;
    built(1, 1, n);
    while(qr--){
        int x, val;
        scani2(x, val);
        update(1, 1, n, x, val);
        write(Tree[1]);
    }
    return 0;
}


// exocodeforce.cpp : Ce fichier contient la fonction 'main'. L'exécution du programme commence et se termine à cet endroit.
//

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

#define mp make_pair
#define pb push_back
//#define long long ll

#define vi vector<int>
#define vd vector<double>
#define rep(i,a,b) for(int i=a;i<b;++i)

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
 const int N = 200005;

int A[200005]={0};
int B[800020]={0};
int st[800020];
void ass(int x){

    while(x){

        rep(p,x/2,x){
            B[p]=1-B[p];
        }
        x/=8;
    }
}

void build(int p,int l,int r) {
    if(l==r) st[p]=A[l];
    else{
        int mid=(l+r)>>1;
        build(2*p,l,mid);
        build(2*p+1,mid+1,r);
     if(B[p]) st[p]=st[2*p]|st[2*p+1];
     else{
         st[p]=st[2*p]^st[2*p+1];
     }
    }

}

void update(int p,int l,int r,int pos,int new_value){
    int i=pos,j=pos;
    if(j<l||r<i) return;
    if(i<=l&&r<=j) st[p]=new_value;
    else{
        int mid=(l+r)>>1;
        if(mid<pos) update(2*p+1,mid+1,r,pos,new_value);
        else update(2*p,l,mid,pos,new_value);
        if(B[p]) st[p]=(st[2*p]|st[2*p+1]);
        else{
         st[p]=(st[2*p]^st[2*p+1]);
         }
    }
}
void Update(int pos,int new_value,int r){
    update(1,0,r,pos-1,new_value);
}

int main()
{ios_base::sync_with_stdio(false);cin.tie(NULL);
int n,m,pos,new_value;

cin>>n>>m;
n=(1<<n);
rep(i,0,n){
   cin>>A[i];
}

ass(n);
build(1,0,n-1);
rep(i,0,m){
    cin>>pos>>new_value;
    Update(pos,new_value,n-1);
    cout<<st[1]<<"\n";
}

  return 0;
}


// exocodeforce.cpp : Ce fichier contient la fonction 'main'. L'exécution du programme commence et se termine à cet endroit.
//

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

#define mp make_pair
#define pb push_back
//#define long long ll

#define vi vector<int>
#define vd vector<double>
#define rep(i,a,b) for(int i=a;i<b;++i)

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
 int N=131073;

ll A[131073]={0};
int B[262145]={0};
void ass(int x){
    for(int p=262144;p>=x;--p) B[p]=1;
    while(x){

        rep(p,x/2,x){
            B[p]=1-B[p];
        }
        x/=8;
    }
}

ll st[4*N];

void build(int p,int l,int r) {
    if(l==r) st[p]=A[l];
    else{
        int mid=(l+r)>>1;
        build(2*p,l,mid);
        build(2*p+1,mid+1,r);
     if(B[p]) st[p]=(st[2*p]|st[2*p+1]);
     else{
         st[p]=(st[2*p]^st[2*p+1]);
     }
    }

}

void update(int p,int l,int r,int pos,ll new_value){
    int i=pos,j=pos;
    if(j<l||r<i) return;
    if(i<=l&&r<=j) st[p]=new_value;
    else{
        int mid=(l+r)>>1;
        if(mid<pos) update(2*p+1,mid+1,r,pos,new_value);
        else update(2*p,l,mid,pos,new_value);
        if(B[p]) st[p]=(st[2*p]|st[2*p+1]);
        else{
         st[p]=(st[2*p]^st[2*p+1]);
         }
    }
}
void Update(int pos,int new_value,int r){
    update(1,0,r,pos-1,new_value);
}

int main()
{ios_base::sync_with_stdio(false);cin.tie(NULL);
int n,m,pos,new_value;

cin>>n>>m;
n=(1<<n);
rep(i,0,n){
   cin>>A[i];
}

ass(n);
build(1,0,n-1);
rep(i,0,m){
    cin>>pos>>new_value;
    Update(pos,new_value,n-1);
    cout<<st[1]<<"\n";
}
  return 0;
}


// exocodeforce.cpp : Ce fichier contient la fonction 'main'. L'exécution du programme commence et se termine à cet endroit.
//

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

#define mp make_pair
#define pb push_back
//#define long long ll

#define vi vector<int>
#define vd vector<double>
#define rep(i,a,b) for(int i=a;i<b;++i)

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
 int N=131073;

ll A[131073]={0};
int B[262145]={0};
void ass(int x){
    for(int p=262144;p>=x;--p) B[p]=1;
    while(x){

        rep(p,x/2,x){
            B[p]=1-B[p];
        }
        x/=8;
    }
}

ll st[524289];

void build(int p,int l,int r) {
    if(l==r) st[p]=A[l];
    else{
        int mid=(l+r)>>1;
        build(2*p,l,mid);
        build(2*p+1,mid+1,r);
     if(B[p]) st[p]=(st[2*p]|st[2*p+1]);
     else{
         st[p]=(st[2*p]^st[2*p+1]);
     }
    }

}

void update(int p,int l,int r,int pos,ll new_value){
    int i=pos,j=pos;
    if(j<l||r<i) return;
    if(i<=l&&r<=j) st[p]=new_value;
    else{
        int mid=(l+r)>>1;
        if(mid<pos) update(2*p+1,mid+1,r,pos,new_value);
        else update(2*p,l,mid,pos,new_value);
        if(B[p]) st[p]=(st[2*p]|st[2*p+1]);
        else{
         st[p]=(st[2*p]^st[2*p+1]);
         }
    }
}
void Update(int pos,int new_value,int r){
    update(1,0,r,pos-1,new_value);
}

int main()
{ios_base::sync_with_stdio(false);cin.tie(NULL);
int n,m,pos,new_value;

cin>>n>>m;
n=(1<<n);
rep(i,0,n){
   cin>>A[i];
}

ass(n);
build(1,0,n-1);
rep(i,0,m){
    cin>>pos>>new_value;
    Update(pos,new_value,n-1);
    cout<<st[1]<<"\n";
}
  return 0;
}


// exocodeforce.cpp : Ce fichier contient la fonction 'main'. L'exécution du programme commence et se termine à cet endroit.
//

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

#define mp make_pair
#define pb push_back
//#define long long ll

#define vi vector<int>
#define vd vector<double>
#define rep(i,a,b) for(int i=a;i<b;++i)

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
bool flag=true;
int combine1(const int &a,const int&b ){
     return (a|b);

}
int combine2(const int &a,const int&b ){
     return (a^b);

}
const ll N=(1<<17)+1;
int A[N];int B[N]={0};
void ass(int x){

    while(x){

        rep(p,x/2,x){
            B[p]=1-B[p];
        }
        x/=8;
    }
}

int st[4*N];
int  pair=0;
void build(int p,int l,int r) {
    if(l==r) st[p]=A[l];
    else{
        int mid=(l+r)>>1;
        build(2*p,l,mid);
        build(2*p+1,mid+1,r);
     if(B[p]) st[p]=(st[2*p]|st[2*p+1]);
     else{
         st[p]=(st[2*p]^st[2*p+1]);
     }
    }

}

void update(int p,int l,int r,int pos,int new_value){
    int i=pos,j=pos;
    if(j<l||r<i) return;
    if(i<=l&&r<=j) st[p]=new_value;
    else{
        int mid=(l+r)>>1;
        if(mid<pos) update(2*p+1,mid+1,r,pos,new_value);
        else update(2*p,l,mid,pos,new_value);
        if(B[p]) st[p]=(st[2*p]|st[2*p+1]);
        else{
         st[p]=(st[2*p]^st[2*p+1]);
         }
    }
}
void Update(int pos,int new_value,int r){
    update(1,0,r,pos-1,new_value);
}

int main()
{ios_base::sync_with_stdio(false);cin.tie(NULL);
int n,m,pos,new_value;

cin>>n>>m;
n=(1<<n);
rep(i,0,n){
   cin>>A[i];
}

ass(n);
build(1,0,n-1);
rep(i,0,m){
    cin>>pos>>new_value;
    Update(pos,new_value,n-1);
    cout<<st[1]<<"\n";
}
  return 0;
}


// exocodeforce.cpp : Ce fichier contient la fonction 'main'. L'exécution du programme commence et se termine à cet endroit.
//

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

#define mp make_pair
#define pb push_back
//#define long long ll

#define vi vector<int>
#define vd vector<double>
#define rep(i,a,b) for(int i=a;i<b;++i)

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
bool flag=true;
int combine1(const int &a,const int&b ){
     return (a|b);

}
int combine2(const int &a,const int&b ){
     return (a^b);

}
const ll N=(1<<17)+1;
int A[N];int B[2*N]={0};
void ass(int x){

    while(x){

        rep(p,x/2,x){
            B[p]=1-B[p];
        }
        x/=8;
    }
}

int st[4*N];
int  pair=0;
void build(int p,int l,int r) {
    if(l==r) st[p]=A[l];
    else{
        int mid=(l+r)>>1;
        build(2*p,l,mid);
        build(2*p+1,mid+1,r);
     if(B[p]) st[p]=(st[2*p]|st[2*p+1]);
     else{
         st[p]=(st[2*p]^st[2*p+1]);
     }
    }

}

void update(int p,int l,int r,int pos,int new_value){
    int i=pos,j=pos;
    if(j<l||r<i) return;
    if(i<=l&&r<=j) st[p]=new_value;
    else{
        int mid=(l+r)>>1;
        if(mid<pos) update(2*p+1,mid+1,r,pos,new_value);
        else update(2*p,l,mid,pos,new_value);
        if(B[p]) st[p]=(st[2*p]|st[2*p+1]);
        else{
         st[p]=(st[2*p]^st[2*p+1]);
         }
    }
}
void Update(int pos,int new_value,int r){
    update(1,0,r,pos-1,new_value);
}

int main()
{ios_base::sync_with_stdio(false);cin.tie(NULL);
int n,m,pos,new_value;

cin>>n>>m;
n=(1<<n);
rep(i,0,n){
   cin>>A[i];
}

ass(n);
build(1,0,n-1);
rep(i,0,m){
    cin>>pos>>new_value;
    Update(pos,new_value,n-1);
    cout<<st[1]<<"\n";
}
  return 0;
}


// exocodeforce.cpp : Ce fichier contient la fonction 'main'. L'exécution du programme commence et se termine à cet endroit.
//

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

#define mp make_pair
#define pb push_back
//#define long long ll

#define vi vector<int>
#define vd vector<double>
#define rep(i,a,b) for(int i=a;i<b;++i)

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
 const int N = 200005;

int A[200005];
int B[800020]={0};
int st[800020];
void ass(int x){

    while(x){

        rep(p,x/2,x){
            B[p]=1-B[p];
        }
        x/=4;
    }
}

void build(int p,int l,int r) {
    if(l==r) st[p]=A[l];
    else{
        int mid=(l+r)>>1;
        build(2*p,l,mid);
        build(2*p+1,mid+1,r);
     if(B[p]) st[p]=st[2*p]|st[2*p+1];
     else{
         st[p]=st[2*p]^st[2*p+1];
        }
    }

}

void update(int p,int l,int r,int pos,int new_value){
    int i=pos,j=pos;
    if(j<l||r<i) return;
    if(i<=l&&r<=j) st[p]=new_value;
    else{
        int mid=(l+r)>>1;
        if(mid<pos) update(2*p+1,mid+1,r,pos,new_value);
        else update(2*p,l,mid,pos,new_value);
        if(B[p]) st[p]=(st[2*p]|st[2*p+1]);
        else{
         st[p]=(st[2*p]^st[2*p+1]);
         }
    }
}
void Update(int pos,int new_value,int r){
    update(1,0,r,pos-1,new_value);
}

int main()
{ios_base::sync_with_stdio(false);cin.tie(NULL);
int n,m,pos,new_value;

cin>>n>>m;
n=1<<n;
rep(i,0,n){
   cin>>A[i];
}

ass(n);
build(1,0,n-1);
rep(i,0,m){
    cin>>pos>>new_value;
    Update(pos,new_value,n-1);
    cout<<st[1]<<"\n";
}

  return 0;
}


// exocodeforce.cpp : Ce fichier contient la fonction 'main'. L'exécution du programme commence et se termine à cet endroit.
//

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

#define mp make_pair
#define pb push_back
//#define long long ll

#define vi vector<int>
#define vd vector<double>
#define rep(i,a,b) for(int i=a;i<b;++i)

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
 const int N = 200005;

int A[200005]={0};
int B[800020]={0};
int st[800020];
void ass(int x){

    while(x){

        rep(p,x/2,x){
            B[p]=1-B[p];
        }
        x/=8;
    }
}

void build(int p,int l,int r) {
    if(l==r) st[p]=A[l];
    else{
        int mid=(l+r)>>1;
        build(2*p,l,mid);
        build(2*p+1,mid+1,r);
     if(B[p]) st[p]=st[2*p]|st[2*p+1];
     else{
         st[p]=st[2*p]^st[2*p+1];
     }
    }

}

void update(int p,int l,int r,int pos,int new_value){
    int i=pos,j=pos;
    if(j<l||r<i) return;
    if(i<=l&&r<=j) st[p]=new_value;
    else{
        int mid=(l+r)>>1;
        if(mid<pos) update(2*p+1,mid+1,r,pos,new_value);
        else update(2*p,l,mid,pos,new_value);
        if(B[p]) st[p]=(st[2*p]|st[2*p+1]);
        else{
         st[p]=(st[2*p]^st[2*p+1]);
         }
    }
}
void Update(int pos,int new_value,int r){
    update(1,0,r,pos-1,new_value);
}

int main()
{ios_base::sync_with_stdio(false);cin.tie(NULL);
int n,m,pos,new_value;

cin>>n>>m;
n=(1<<n);
rep(i,0,n){
   cin>>A[i];
}

ass(n);
build(1,0,n-1);
rep(i,0,m){
    cin>>pos>>new_value;
    Update(pos,new_value,n-1);
    cout<<st[1]<<"\n";
}
cout<<4*N;
  return 0;
}


// exocodeforce.cpp : Ce fichier contient la fonction 'main'. L'exécution du programme commence et se termine à cet endroit.
//

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

#define mp make_pair
#define pb push_back
//#define long long ll

#define vi vector<int>
#define vd vector<double>
#define rep(i,a,b) for(int i=a;i<b;++i)

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
bool flag=true;
int combine1(const int &a,const int&b ){
     return (a|b);

}
int combine2(const int &a,const int&b ){
     return (a^b);

}
const int N=(1<<17)+1;
int A[N];int B[N]={0};
void ass(int x){

    while(x){

        rep(p,x/2,x){
            B[p]=1-B[p];
        }
        x/=8;
    }
}

int st[4*N];
int  pair=0;
void build(int p,int l,int r) {
    if(l==r) st[p]=A[l];
    else{
        int mid=(l+r)>>1;
        build(2*p,l,mid);
        build(2*p+1,mid+1,r);
     if(B[p]) st[p]=(st[2*p]|st[2*p+1]);
     else{
         st[p]=(st[2*p]^st[2*p+1]);
     }
    }

}

void update(int p,int l,int r,int pos,int new_value){
    int i=pos,j=pos;
    if(j<l||r<i) return;
    if(i<=l&&r<=j) st[p]=new_value;
    else{
        int mid=(l+r)>>1;
        if(mid<pos) update(2*p+1,mid+1,r,pos,new_value);
        else update(2*p,l,mid,pos,new_value);
        if(B[p]) st[p]=(st[2*p]|st[2*p+1]);
        else{
         st[p]=(st[2*p]^st[2*p+1]);
         }
    }
}
void Update(int pos,int new_value,int r){
    update(1,0,r,pos-1,new_value);
}

int main()
{ios_base::sync_with_stdio(false);cin.tie(NULL);
int n,m,pos,new_value;

cin>>n>>m;
n=(1<<n);
rep(i,0,n){
   cin>>A[i];
}

ass(n);
build(1,0,n-1);
rep(i,0,m){
    cin>>pos>>new_value;
    Update(pos,new_value,n-1);
    cout<<st[1]<<"\n";
}
  return 0;
}


// exocodeforce.cpp : Ce fichier contient la fonction 'main'. L'exécution du programme commence et se termine à cet endroit.
//

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

#define mp make_pair
#define pb push_back
//#define long long ll

#define vi vector<int>
#define vd vector<double>
#define rep(i,a,b) for(int i=a;i<b;++i)

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;

ll N=(1<<17)+1;
int A[N];int B[2*N]={0};
void ass(int x){
    for(int p=2*N-1;p>=x;--p) B[p]=1;
    while(x){

        rep(p,x/2,x){
            B[p]=1-B[p];
        }
        x/=8;
    }
}

int st[4*N];

void build(int p,int l,int r) {
    if(l==r) st[p]=A[l];
    else{
        int mid=(l+r)>>1;
        build(2*p,l,mid);
        build(2*p+1,mid+1,r);
     if(B[p]) st[p]=(st[2*p]|st[2*p+1]);
     else{
         st[p]=(st[2*p]^st[2*p+1]);
     }
    }

}

void update(int p,int l,int r,int pos,int new_value){
    int i=pos,j=pos;
    if(j<l||r<i) return;
    if(i<=l&&r<=j) st[p]=new_value;
    else{
        int mid=(l+r)>>1;
        if(mid<pos) update(2*p+1,mid+1,r,pos,new_value);
        else update(2*p,l,mid,pos,new_value);
        if(B[p]) st[p]=(st[2*p]|st[2*p+1]);
        else{
         st[p]=(st[2*p]^st[2*p+1]);
         }
    }
}
void Update(int pos,int new_value,int r){
    update(1,0,r,pos-1,new_value);
}

int main()
{ios_base::sync_with_stdio(false);cin.tie(NULL);
int n,m,pos,new_value;

cin>>n>>m;
n=(1<<n);
rep(i,0,n){
   cin>>A[i];
}

ass(n);
build(1,0,n-1);
rep(i,0,m){
    cin>>pos>>new_value;
    Update(pos,new_value,n-1);
    cout<<st[1]<<"\n";
}
  return 0;
}


#include "bits/stdc++.h"
using namespace std;
const int N = 1 << 17 ;
int tree[N * 4][2], a[N];

void update(int node, int st, int ed, int pos, int val)
{
        if(st > ed) return ;
        if(st == ed) {
                if(st == pos) {
                        tree[node][0] = val;
                }
                return ;
        }
        int mid = (st + ed) >> 1;
        tree[node * 2][1] = tree[node * 2 + 1][1] = tree[node][1] ^ 1;
        update(node * 2, st, mid, pos, val);
        update(node * 2 + 1, mid + 1, ed, pos, val);
        if (tree[node][1]) tree[node][0] = tree[node * 2][0] | tree[node * 2 + 1][0];
        else tree[node][0] = tree[node * 2][0] ^ tree[node * 2 + 1][0];
}

int main()
{
        int n, m;
        scanf("%d %d", &n, &m);
        if(n & 1) tree[1][1] = 1;
        n = 1 << n;
        for(int i = 0; i < n; i++) scanf("%d", a + i), update(1, 0, n - 1, i, a[i]);
        while(m--) {
                int pos, val;
                scanf("%d %d", &pos, &val);
                update(1, 0, n - 1, pos - 1, val);
                printf("%d\n", tree[1][0]);
        }
        return 0;
}


#include "bits/stdc++.h"
using namespace std;
const int N = 1 << 17 ;
int tree[N * 4][2], a[N];

void update(int node, int st, int ed, int pos, int val)
{
        if(st > ed) return ;
        if(st == ed) {
                if(st == pos) {
                        tree[node][0] = val;
                }
                return ;
        }
        int mid = (st + ed) >> 1;
        tree[node * 2][1] = tree[node * 2 + 1][1] = tree[node][1] ^ 1;
        update(node * 2, st, mid, pos, val);
        update(node * 2 + 1, mid + 1, ed, pos, val);
        if (tree[node][1]) tree[node][0] = tree[node * 2][0] | tree[node * 2 + 1][0];
        else tree[node][0] = tree[node * 2][0] ^ tree[node * 2 + 1][0];
}

int main()
{
        int n, m;
        scanf("%d %d", &n, &m);
        n = 1 << n;
        for(int i = 0; i < n; i++) scanf("%d", a + i), update(1, 0, n - 1, i, a[i]);

        while(m--) {
                int pos, val;
                scanf("%d %d", &pos, &val);
                update(1, 0, n - 1, pos - 1, val);
                printf("%d\n", tree[1][0]);
                //update(1, 0, n - 1, pos - 1, a[ pos - 1 ]);
        }

        return 0;
}


/**
* @author Ashini Singha
* IIT,Jahangirnagar University
*/
#include<bits/stdc++.h>
using namespace std;
#define     ll          long long int
#define     fo(i,b,n)   for(int i=(b); i<(n) ; i++)
#define     xx          first
#define     yy          second
#define     pb          push_back
#define     sz(n)       int(n.size())
#define     pii         pair
#define     MP          make_pair

#define     PI          acos(-1.0)

#define read(x)         scanf("%d",&x)
#define read2(x,y)      scanf("%d%d",&x,&y)
#define readl(x)        scanf("%lld",&x)
#define readl2(x,y)     scanf("%lld%lld",&x,&y)
#define readd(x)        scanf("%lf",&x)
#define readd2(x,y)     scanf("%lf%lf",&x,&y)

#define pr(n)           printf("%d",n)
#define prn(n)          printf("%d\n",n)
#define prl(n)          printf("%lld",n)
#define prln(n)         printf("%lld\n",n)
#define prd(x)          printf("%lf",x)
#define prdn(x)         printf("%lf\n",x)
#define TC(n) printf("Case %d: ",n)
/*_____________E_N_D______________*/

const int N = 1234567;
int tree[N];

void build(int node, int st, int ed, int idx, int value, int flag)
{
      if(st == ed && st == idx ) {
            tree[node] = value;
            return ;
      }
      int mid = (st + ed) >> 1;
      if( idx <= mid ) build(node * 2, st, mid, idx, value, flag - 1);
      else build(node * 2 + 1, mid + 1, ed, idx, value, flag - 1);
      if(flag & 1) tree[node] = tree[node * 2] | tree[node * 2 + 1];
      else tree[node] = tree[node * 2] ^ tree[node * 2 + 1];
      return ;
}

int main()
{
      int n, m;
      read2(n, m);
      int lim = 1 << n;

      fo(i, 1, lim + 1) {
            int x;
            read(x);
            build(1, 1, lim, i, x, n);
      }
      while(m--) {
            int pos, val;
            read2(pos, val);
            build(1, 1, lim, pos, val, n);
            prn(tree[1]);

      }
      return 0;
}


#include "bits/stdc++.h"
using namespace std;
const int N = 1 << 17 ;
int tree[N * 4][2], a[N];

void update(int node, int st, int ed, int pos, int val)
{
        if(st > ed) return ;
        if(st == ed) {
                if(st == pos) {
                        tree[node][0] = val;
                }
                return ;
        }
        int mid = (st + ed) >> 1;
        tree[node * 2][1] = tree[node * 2 + 1][1] = tree[node][1] ^ 1;
        if(pos <= mid)
                update(node * 2, st, mid, pos, val);
        else
                update(node * 2 + 1, mid + 1, ed, pos, val);
        if (tree[node][1]) tree[node][0] = tree[node * 2][0] | tree[node * 2 + 1][0];
        else tree[node][0] = tree[node * 2][0] ^ tree[node * 2 + 1][0];
}

int main()
{
        int n, m;
        scanf("%d %d", &n, &m);
        if(n & 1) tree[1][1] = 1;
        n = 1 << n;
        for(int i = 0; i < n; i++) scanf("%d", a + i), update(1, 0, n - 1, i, a[i]);
        while(m--) {
                int pos, val;
                scanf("%d %d", &pos, &val);
                update(1, 0, n - 1, pos - 1, val);
                printf("%d\n", tree[1][0]);
        }
        return 0;
}


#include "bits/stdc++.h"
using namespace std;
const int N = 1 << 17 ;
int tree[N * 4];

void update(int node, int st, int ed, int pos, int val, int flag)
{
        //cout << st << " " << ed << " " << flag << endl;
        if(st == ed && st == pos) {
                tree[node] = val;
                return ;
        }
        int mid = (st + ed) >> 1;

        if(pos <= mid) update(node * 2, st, mid, pos, val, flag - 1);
        else update(node * 2 + 1, mid + 1, ed, pos, val, flag - 1);

        if(flag&1) tree[node] = tree[node * 2] | tree[node * 2 + 1];
        else tree[node] = tree[node * 2] ^ tree[node * 2 + 1];

}

int main()
{
        int n, q, x;
        scanf("%d %d", &n, &q);
        n = 1 << n;
        for(int i = 0; i < n; i++) scanf("%d", &x), update(1, 0, n - 1, i, x, n);
        while(q--) {
                int pos, val;
                scanf("%d %d", &pos, &val);
                update(1, 0, n - 1, pos - 1, val, n);
                printf("%d\n", tree[1]);
        }
        return 0;
}


#include "bits/stdc++.h"
using namespace std;
const int N = 1 << 17 ;
int tree[N * 4][2], a[N];

void init(int node, int st, int ed)
{
        if(st == ed) {
                tree[node][0] = a[st];
                return ;
        }
        int mid = (st + ed) >> 1;
        tree[node * 2][1] = tree[node * 2 + 1][1] = tree[node][1] ^ 1;
        init(node * 2, st, mid);
        init(node * 2 + 1, mid + 1, ed);
        if (tree[node][1]) tree[node][0] = tree[node * 2][0] | tree[node * 2 + 1][0];
        else tree[node][0] = tree[node * 2][0] ^ tree[node * 2 + 1][0];
}

void update(int node, int st, int ed, int pos, int val)
{
        if(st > ed) return ;
        if(st == ed) {
                if(st == pos) {
                        tree[node][0] = val;
                }
                return ;
        }
        int mid = (st + ed) >> 1;
        update(node * 2, st, mid, pos, val);
        update(node * 2 + 1, mid + 1, ed, pos, val);
        if (tree[node][1]) tree[node][0] = tree[node * 2][0] | tree[node * 2 + 1][0];
        else tree[node][0] = tree[node * 2][0] ^ tree[node * 2 + 1][0];
}

int main()
{
        int n, m;
        scanf("%d %d", &n, &m);
        if(n & 1) tree[1][1] = 1;
        n = 1 << n;
        for(int i = 0; i < n; i++) scanf("%d", a + i);
        init(1, 0, n - 1);
        while(m--) {
                int pos, val;
                scanf("%d %d", &pos, &val);
                update(1, 0, n - 1, pos - 1, val);
                printf("%d\n", tree[1][0]);
        }
        return 0;
}


/**
* @author Ashini Singha
* IIT,Jahangirnagar University
*/
#include<bits/stdc++.h>
using namespace std;
#define     ll          long long int
#define     fo(i,b,n)   for(int i=(b); i<(n) ; i++)
#define     xx          first
#define     yy          second
#define     pb          push_back
#define     sz(n)       int(n.size())
#define     pii         pair
#define     MP          make_pair

#define     PI          acos(-1.0)

#define read(x)         scanf("%d",&x)
#define read2(x,y)      scanf("%d%d",&x,&y)
#define readl(x)        scanf("%lld",&x)
#define readl2(x,y)     scanf("%lld%lld",&x,&y)
#define readd(x)        scanf("%lf",&x)
#define readd2(x,y)     scanf("%lf%lf",&x,&y)

#define pr(n)           printf("%d",n)
#define prn(n)          printf("%d\n",n)
#define prl(n)          printf("%lld",n)
#define prln(n)         printf("%lld\n",n)
#define prd(x)          printf("%lf",x)
#define prdn(x)         printf("%lf\n",x)
#define TC(n) printf("Case %d: ",n)
/*_____________E_N_D______________*/

const int N = 123456;
int tree[N];

void build(int node, int st, int ed, int idx, int value, int flag)
{
      if(st == ed && st == idx ) {
            tree[node] = value;
            return ;
      }
      int mid = (st + ed) >> 1;
      if( idx <= mid ) build(node * 2, st, mid, idx, value, flag - 1);
      else build(node * 2 + 1, mid + 1, ed, idx, value, flag - 1);
      if(flag & 1) tree[node] = tree[node * 2] | tree[node * 2 + 1];
      else tree[node] = tree[node * 2] ^ tree[node * 2 + 1];
      return ;
}

int main()
{
      int n, m;
      read2(n, m);
      int lim = 1 << n;

      fo(i, 1, lim + 1) {
            int x;
            read(x);
            build(1, 1, lim, i, x, n);
      }
      while(m--) {
            int pos, val;
            read2(pos, val);
            build(1, 1, lim, pos, val, n);
            prn(tree[1]);

      }
      return 0;
}


#include<iostream>
#include<math.h>
#include<vector>
using namespace std;
typedef long long int lli;

struct data{
	lli value,flag;
	data(lli value1, lli flag1){
		value=value1;
		flag=flag1;
	}
};

class STree{
	public:
	lli NLeaf;
	lli size;	//Tree size

//	data=new *tree[];	//tree base 0...
	//Stock** StockArrayArray = new Stock*[n]; // where n is number of arrays to create
	data **tree;
	data **arr;	//array base //leaf base // NLeaf+1...size

	STree(lli n , vector<lli> vec1);
	void initilize();
	void showTree();

	void update(lli i);
	void changeBaseNode(lli idx, lli value);
	lli returnRoot();

};

lli STree::returnRoot(){
	return tree[0]->value;
}

void STree::changeBaseNode(lli idx, lli value){
	if(arr[idx]->value==value) return;
	arr[idx]->value=value;
	lli bidxForTre=idx+NLeaf-1;
	update(bidxForTre);	//array index and tree index relationship
}

void STree::update(lli k){
	lli par=(k-1)/2;
//	cout<<"Inside update\n";
	while(1){

		lli ch1=2*par +1;
		lli ch2=ch1+1;
//		cout<<par<<"\t"<<ch1<<" "<<ch2<<endl;
		lli flag=tree[ch1]->flag;
		if(flag==1)//or operation
			tree[par]->value=tree[ch1]->value | tree[ch2]->value;
		else //Xor
			tree[par]->value=tree[ch1]->value ^ tree[ch2]->value;

		if(par==0) break;
		par=(par-1)/2;
	}

}
int main(){

	lli n,m;
	cin>>n>>m;
	lli size=pow(2,n);
	vector<lli> vec1;
	for(lli i=0;i<size;i++){
		lli temp;
		cin>>temp;
		vec1.push_back(temp);
	}
//	cout<<"Creating segment Tree object\n";
	class STree t=*(new STree(vec1.size(),vec1));
//	cout<<"Prlliing the tree so Formed\n";
//	t.showTree();
	//cout<<endl<<endl;

	//Taking Care of Query
	for(lli i=0;i<m;i++){
		lli idx,value;
		cin>>idx>>value;
		idx--;
		t.changeBaseNode(idx,value);
	//	t.showTree();
		lli ans=t.returnRoot();
	//	cout<<"ANS: "<<ans<<endl;
		cout<<ans<<endl;
	}

}

STree::STree(lli n,vector<lli> vec1){
		NLeaf=n;
		size=NLeaf + (NLeaf-1);
//		cout<<"The totaol size is\t"<<size<<endl;

	//	tree=new data[size];
		tree=new data*[size];
		arr=tree + (NLeaf-1);
	//	cout<<"Distance between *tree and *arr is\t"<<arr-tree<<endl;

		for(lli i=0;i<vec1.size();i++){
			arr[i]=new data(vec1[i],1);
		}
		initilize();

	}

void STree::showTree(){

	lli k=1;
	for(lli i=0;i<size;i++){
		cout<<tree[i]->value<<"["<<tree[i]->flag<<","<<i<<"]"<<" ";
		if(i==0 || i==2 || i==6 || i==14) cout<<endl;
	}

	cout<<"\nPrlliing only the leaf part\n";
	for(lli i=0;i<NLeaf;i++)
		cout<<arr[i]->value<<" ";
}
void STree::initilize(){
	lli a,b;
	a=2;b=4;

	lli flag=0;
	for(lli i =NLeaf-2;i>=0;i--){
		lli par=i;
		lli ch1,ch2;
		ch1=2*i +1;
		ch2=ch1+1;
		lli flag=tree[ch1]->flag;
		if(flag==1)//do OR
			tree[i]=new data(tree[ch1]->value | tree[ch2]->value, !flag);
		else //do XOR
			tree[i]=new data(tree[ch1]->value ^ tree[ch2]->value, !flag);

	}
}


#include<iostream>
#include<math.h>
#include<vector>
using namespace std;
typedef long long int lli;

struct data{
	lli value,flag;
	data(lli value1, lli flag1){
		value=value1;
		flag=flag1;
	}
};

class STree{
	public:
	lli NLeaf;
	lli size;	//Tree size

//	data=new *tree[];	//tree base 0...
	//Stock** StockArrayArray = new Stock*[n]; // where n is number of arrays to create
	data **tree;
	data **arr;	//array base //leaf base // NLeaf+1...size

	STree(lli n , vector<lli> vec1);
	void initilize();
	void showTree();

	void update(lli i);
	void changeBaseNode(lli idx, lli value);
	lli returnRoot();

};

lli STree::returnRoot(){
	return tree[0]->value;
}

void STree::changeBaseNode(lli idx, lli value){
	arr[idx]->value=value;
	lli bidxForTre=idx+NLeaf-1;
	update(bidxForTre);	//array index and tree index relationship
}

void STree::update(lli k){
	lli par=(k-1)/2;
//	cout<<"Inside update\n";
	while(1){

		lli ch1=2*par +1;
		lli ch2=ch1+1;
//		cout<<par<<"\t"<<ch1<<" "<<ch2<<endl;
		lli flag=tree[ch1]->flag;
		if(flag==1)//or operation
			tree[par]->value=tree[ch1]->value | tree[ch2]->value;
		else //Xor
			tree[par]->value=tree[ch1]->value ^ tree[ch2]->value;

		if(par==0) break;
		par=(par-1)/2;
	}

}
int main(){

	lli n,m;
	cin>>n>>m;
	lli size=pow(2,n);
	vector<lli> vec1;
	for(lli i=0;i<size;i++){
		lli temp;
		cin>>temp;
		vec1.push_back(temp);
	}
//	cout<<"Creating segment Tree object\n";
	class STree t=*(new STree(vec1.size(),vec1));
//	cout<<"Prlliing the tree so Formed\n";
//	t.showTree();
	//cout<<endl<<endl;

	//Taking Care of Query
	for(lli i=0;i<m;i++){
		lli idx,value;
		cin>>idx>>value;
		idx--;
		t.changeBaseNode(idx,value);
	//	t.showTree();
		lli ans=t.returnRoot();
	//	cout<<"ANS: "<<ans<<endl;
		cout<<ans<<endl;
	}

}

STree::STree(lli n,vector<lli> vec1){
		NLeaf=n;
		size=NLeaf + (NLeaf-1);
//		cout<<"The totaol size is\t"<<size<<endl;

	//	tree=new data[size];
		tree=new data*[size];
		arr=tree + (NLeaf-1);
	//	cout<<"Distance between *tree and *arr is\t"<<arr-tree<<endl;

		for(lli i=0;i<vec1.size();i++){
			arr[i]=new data(vec1[i],1);
		}
		initilize();

	}

void STree::showTree(){

	lli k=1;
	for(lli i=0;i<size;i++){
		cout<<tree[i]->value<<"["<<tree[i]->flag<<","<<i<<"]"<<" ";
		if(i==0 || i==2 || i==6 || i==14) cout<<endl;
	}

	cout<<"\nPrlliing only the leaf part\n";
	for(lli i=0;i<NLeaf;i++)
		cout<<arr[i]->value<<" ";
}
void STree::initilize(){
	lli a,b;
	a=2;b=4;

	lli flag=0;
	for(lli i =NLeaf-2;i>=0;i--){
		lli par=i;
		lli ch1,ch2;
		ch1=2*i +1;
		ch2=ch1+1;
		lli flag=tree[ch1]->flag;
		if(flag==1)//do OR
			tree[i]=new data(tree[ch1]->value | tree[ch2]->value, !flag);
		else //do XOR
			tree[i]=new data(tree[ch1]->value ^ tree[ch2]->value, !flag);

	}
}


//Xenia and Bit Operations
#include<iostream>
#include<math.h>
using namespace std;

class segmentTree
{	//NOTE: 	the index in sBase starts from 1
	int SArray;	//is the number of data in the
	int NNode;	//no. of nodes in the final segment tree
	int *sBase;
	int sIn,eIn;	//start and end index of the array, from where the array is copied in the the segmentTree

	public:
	int findBase()
	{
		return sBase[1];
	}
	segmentTree(int arr[],int NElem1)
	{
		SArray=NElem1;
		NNode=(2*NElem1) -1;//Total number of nodes in segment tree

		sIn=SArray;			//can be clerified with the pic, saved in the program folder
		eIn= SArray +SArray -1;

		sBase=new int[NNode]();

		for(int i=sIn;i<=eIn;i++)
		{
			sBase[i]=arr[i-sIn];
		}
	}
	void printTree();

	int query(int l,int r)		//the interval is [l,r) ; NOTE: r is not inlcuded
	{
		l=l+SArray;
		r=r+SArray+1;	//mapping the array index to the tree index
		int val=0;
		for(;l<r; l>>=1,r>>=1)	//l>>=1 means l/2; i.e divide l by 2
		{
			if(l &1==1)	//if l is odd
				val=val+sBase[l++];	//add sBase[l] and increment l by 1; so that in for loop l becomes the parent of itserf
			if(r & 1 ==1)
				val=val+sBase[--r];	//add sBase[r-1] to val; as it will be not in paris in pic
			//se pic on codeforce for more detail, if you had forgetten
		}
		return val;
	}
	void update(int ind,int val)	//value at sBase[ind+NArray] has to chaged in val
	{
		int i=ind+SArray;
		int flag=1;
		for(sBase[i]=val; i>=1;i=i/2)
		{	int par=i/2;
			int ch1=par*2,ch2=ch1+1;
			if(flag==1)
				sBase[par]=sBase[ch1] | sBase[ch2];
			if(flag==0)
				sBase[par]=sBase[ch1] ^ sBase[ch2];

			if(flag==1) flag=0;
			else flag=1;
		}

	}

	void inilization()
	{
		int NTime=SArray/2;
		int flag=1;	// 1 means do or operation

		int i=sIn-1;
		while(1)
		{
			for(int k=0;k<NTime && i>=1;k++,i--)
			{
				if(flag==1)
					sBase[i]=sBase[2*i] | sBase[2*i+1];
				if(flag==0)
					sBase[i]=sBase[2*i] ^ sBase[2*i+1];
			}
			if(flag==1)	flag=0;
			else flag=1;

			NTime=NTime/2;
			if(NTime==0 || i<1) break;
		}
	}
};

int main()
{
//	//int arr[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
//	//int arr[]={0,1,2,0,4,5,6,7,8,9,10,11,12};
//	int arr[]={2,6,4,5};
//	int SArray=sizeof(arr)/sizeof(arr[0]);
//
//	segmentTree sTree1(arr,SArray);
//	sTree1.inilization();
//	cout<<"\nPrinting the tree formed\n";
//	sTree1.printTree();
//
//	cout<<"\nANSWER IS\n";
//	cout<<sTree1.findBase();

	int num,NQuery;
	cin>>num>>NQuery;
	int SArray=pow(2,num);

	int arr[SArray];

	for(int i=0;i<SArray;i++)
		cin>>arr[i];

	segmentTree sTree2(arr,SArray);
	sTree2.inilization();
	//cout<<"\t";sTree2.printTree();
	//cout<<endl;
	for(int k=0;k<NQuery;k++)
	{
		int ind,val;
		cin>>ind>>val;
		sTree2.update(ind-1,val);

	//	cout<<"\nPrinting the tree\n";
	//	sTree2.printTree();

		cout<<sTree2.findBase()<<endl;
	}

	return 0;
}

void segmentTree::printTree()
{
	for(int i=1;i<=NNode;i++)
	{
		cout<<sBase[i]<<"["<<i<<"]"<<" ";

	}
	cout<<endl;
}


#include<iostream>

#define lson (x<<1)
#define mid ((l + r)>>1)
#define rson (x<<1 | 1)

using namespace std;
const int N = 64;
int n;
int t[N << 2];
int arr[N];
void push_up(int x) {
	t[x] = t[lson] + t[rson];
}

void build1() {
	for (int i = n - 1; i > 0; i--) push_up(i);
}

void build2(int p, int l, int r) {
	if (l > r) return;

	if (l == r) return;
//	if (l == r) { //case of leaf node
	//	t[p] = arr[l];
	// return;
	//}							//SINCE THE DATA HAS ALREADY BEEN ADDED THIS BLOCKS OF NO USE TO US NOW

	build2(2*p, l, (l+r)/2);
	build2(2 * p + 1, 1+(l+r)/2, r);

	push_up(p);
}

//it is a point update
//ALWAYS VALUE: X=1,l=0,r=7
//make t[p+n]=b OR equivalencly arr[p]=b and update tree accordingly
void update1(int x, int l, int r, int p, int b) {
	if (l == r && l==p) {	//NOTICE:- There is only a slight change here, w.r.t update2(..)
		t[x] = b;	//TODO:- Check if x is equal to p+n here
		return;
	}

	if (p <= mid) update1(lson, l, mid, p, b);
	else update1(rson, mid + 1, r, p, b);

	push_up(x);
}

//It is a range update
//will increment value in range [i,j] of array arr[]. And then will update the tree accrodingly
//i,j is based on 0 index as it represents the position in arr[]
//l,r will be passed as l=0,r=n-1 ALWAYS
//x will  be passed as 1 ALWAYS
void update2(int x, int l, int r, const int i, const int j, int val) {
	if (l > r || l > j || r < i) return;
	if (l == r) {
		t[x] += val;
		return;
	}

	update2(lson, l, mid, i, j, val);
	update2(rson, mid + 1, r, i, j, val);

	push_up(x);
}

void printTree();
int main() {
	n = 8;
	for (int i = 0; i < n; i++) t[i + n] = i+1;

	//build();
	build2(1,0,7);
	cout << "Printing the inital tree\n";
	printTree();

	cout << "\nCalling update\n";
	//update2(1, 0, 7, 0, 4, -1);
	update1(1, 0, 7, 3, 14);
	cout << "Printing update tree\n";
	printTree();

	system("pause");
}

void printTree() {
	for (int i = 1; i <2*n; i++) cout << "["<<i<<"]"<<t[i] << " ";
	cout << endl;
}

//int a[N]: this is the array where the original array is stored


#include<iostream>
#include<math.h>
#include<cstring>
#define lson (x<<1)
#define rson (x<<1 |1)
#define mid ((l+r)/2)
#define par (x>>1)
#define mch  if(l!=r)\
                    {\
                    lzy[lson]+=lzy[x]; \
                    lzy[rson]+=lzy[x];\
                    }

using namespace std;

const int N = 1e4 + 2;
int t[N << 2];
int a[N],n, z;
int lzy[N<<2];
int h;

void init() {

	memset(t, 0, sizeof(t));
	memset(lzy,0,sizeof(lzy));
	memset(a, 0, sizeof(a));
	z = 0;
	h=log2(n&-n) + 1;
	cout<<"Initilizatiion done!\n";

}

void push_up(int x) {
	t[x] = t[lson] + t[rson];
}
void show();
void build(int x, int l, int r) {
	if (l == r) {
		t[x] = a[z++];
		return;
	}

	build(lson, l, mid);
	build(rson, mid + 1, r);

	push_up(x);
}

void updateNode(int x, int l, int r, int p, int b) {
	if (l == p && p == r){
        t[x] = b;
        return;
	}

	if (p <= mid) updateNode(lson, l, mid, p, b);
	else updateNode(rson, mid + 1, r, p, b);

	push_up(x);
}

void updateNodeIt(int x, int val){

    for(t[x=x+n]=val;x>1;x>>=1){
        push_up(par);  //update the parent
    }
}
//query(1,0,n-1,i,j) find the query for range [i,j]
int queryREC(int x, int l, int r, int i, int j) {
	if( l> r ||l > j ||r<i) return 0;
	if(l>=i && r<=j) return t[x]; //within range

	return queryREC(lson,l,mid, i,j)
            + queryREC(rson,mid+1 ,r, i ,j);
}

//queryIT paramertes will be [l,r). i.e, the right boundary will not be included here
int queryIT(int l, int r){
    int res=0;
    for(l+=n,r+=n;l<r;l>>=1,r>>=1){
        if(l&1) res+=t[l++];
        if(r&1) res+=t[--r];

    }
    return res;
}

//increment the value
in the range [i,j] to val
//again x,l,r are here for helping us deciding the boundary with inital (x=1,l=0,r=n-1)
void updateRANGE_LAZY(int x, int l, int r, const int i,const int j, const int val,int lvl){
    if(l>r || j<l || r<i) return; //outside range
    if(lzy[x] != 0){//this node is marked lazy, so needs to be updated
        t[x]=t[x] + lzy[x];
        if(l!=r) lzy[lson]+=lzy[x]/2;
        if(l!=r) lzy[rson]+=lzy[x]/2;
        lzy[x]=0;

    }

    if(i<=l && r<=j){//within range

        t[x]+=val*lvl;
        if(l!=r) lzy[lson]+=val*(lvl-1);
        if(l!=r) lzy[rson]+=val*(lvl-1);

        return;
    }

    updateRANGE_LAZY(lson,l,mid,i,j,val,lvl-1);
    updateRANGE_LAZY(rson,mid+1,r,i,j,val,lvl-1);

    push_up(x);//parents of the current node are always up to date. It the theri children which are not up to data, and therfore are marked as lazy

}

int queryLAZY(int x, int l, int r, const int i,  const int j){
        if(l>r || j<l || r<i) return 0; //outside range

        if(lzy[x] != 0){
            t[x]=t[x]+lzy[x];
            mch;
            lzy[x]=0;
        }

        if(i<=l && r<=j) return t[x];//within range

        return queryLAZY(lson,l,mid,i,j)
                + queryLAZY(rson,mid+1,r,i,j);
}

void show() {
	for (int i = 0;i <= 16;i++) cout << t[i] << "["<<i<<"]"<<"   ";
}
int main() {
	//freopen("input1.txt", "r+", stdin);
	freopen("output1.txt","rw+",stdout);

	//cin >> n;
	n=8;
	init();

	for (int i = 0;i<n;i++) a[i]=i+1;

	build(1, 0, n - 1);
	cout << "building of the tree is done\n";
	cout << "now printing\n";
	show();
	cout<<endl;
/*
	cout<<"updating a val using RECURSIVE update\n";
	updateNode(1,0,n-1,1,12);
	show();

    cout<<"\n\nCalling iterative update\n";
    updateNodeIt(1,2);
    show();
    cout<<endl;

    cout<<"Now we are doing queryREC\n";
    cout<<"query val: "<<queryREC(1,0,n-1,3,7)<<endl;

    cout<<"Now calling queryIT\n";
    cout<<" queryIT val: "<<queryIT(3,8)<<endl;
*/
	cout<<"h: "<<h<<endl;
    cout<<"updating in range\n";
    int lvl=h; //root is at the highest level
    updateRANGE_LAZY(1,0,n-1,3,7,10,lvl);
    show();
    cout<<endl;
    cout<<"showing lazy tree\n";
    for (int i = 0;i <= 16;i++) cout << lzy[i] << "["<<i<<"]"<<"   ";

    cout<<"doin query_LAZY: \t";
    cout<<queryLAZY(1,0,n-1,3,7)<<endl;
    cout<<"after query showing the tree\n";
    show();cout<<endl;
    for (int i = 0;i <= 16;i++) cout << lzy[i] << "["<<i<<"]"<<"   ";

    cout<<endl;

    cin>>n;

}

        //if(l!=r) lzy[lson]+=lzy[x];
        //if(l!=r) lzy[rson]+=lzy[x];
        //NOTE: repace mch with above code

//int h;//height of segment tree


//Link: https://www.e-olymp.com/en/problems/1061

#include<iostream>
#include<cstring>
using namespace std;

class Matrix {
	int NRow, NColumn;
public:
	int *mat;
	Matrix(int n, int m) {
		NRow = n;
		NColumn = m;

		mat = (int*)malloc(NRow*NColumn*sizeof(int));
		memset(mat, 0, NRow*NColumn);
	}

	int get(int x, int y) {
		return x + NRow*y;
	}
	void set(int val,int x, int y) {
		mat[x + y*NRow] = val;
	}
};

int matrix[1000][1000];
int visited[1000][1000];
int NRow;
int NColumn;
void init() {
	memset(matrix, 0, 1000000);
	memset(matrix, 0, 1000000);
	NRow = 0;
	NColumn = 0;
}

int inRange(int x, int y) {
	if (x >= 0 && x <= NRow - 1 && y >= 0 && y <= NColumn - 1) return 1;
	return 0;
}

void findCount(int x, int y, int &ans) {
	if (inRange(x, y) == 0) {
		ans++;
		return;
	}

	int val = matrix[x][y];
	if (val == '0') {
		ans++;
		return;
	}

	static int ar1[] = {0,1,0,-1};
	static int ar2[] = {-1,0,1,0};

	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			int nx = x + ar1[i];
			int ny = y + ar2[j];

			if (visited[x][y] == 0) {
				findCount(nx, ny, ans);
			}
		}
	}
}
int main() {
	init();
	int n;
	cin >> n;
	NRow = n;
	NColumn = n;

	for (int i = 0; i < NRow; i++) {
		for (int j = 0; j < NColumn; j++) {
			char c1;
			cin >> c1;
			int val = (c1 == '.') ? 1 : 0;	//'.' means allow them
			matrix[i][j] = val;
		}
	}

	int ans = 0;
	findCount(0, 0, ans);;
}


mailing address: sbibhu@sbi.co.in

Dear Branch Manager,

		I have availed the facility of education loan from you SBI branch. As of now I have just graduated from IIT (BHU).  And I want to close my loan account after paying my dues.
	I have a query about the subsidy you told about, during the opening of my education loan account. As for you information we had submitted income certificate of my parents below 4LPA. I want to know what is the subsidy amount which I will get, if I want to close my education loan account. If I remembered correctly the subsidy amount is perhaps close to 1.5 Lakh (correct me if I am wrong). Also please tell me what I should do to get this subsidy.
Also if possible, Please reply with a phone number of person whom I can contact regarding this matter.

Thanks in advance!

Name:  Pankaj Kumar
Branch: Electronics
University Roll No: 13095047
University:  IIT(BHU)
Education Period:  2013-2017(already graduated)

Account No:- 		20178442528
Loan Account No:- 	33421210518


#include<iostream>
#define lson (x<<1)
#define rson (x<<1|1)
#define mid ((l+r)>>1)
using namespace std;

struct data{
    int gcd,cn;
    data(){
        gcd=0;
        cn=0;
    }
};
int const N=10000;
int n;
struct data t[N<<4];
int findGCD(int ,int);

struct data combine(data lt, data rt){
    struct data nd;

    nd.gcd=findGCD(lt.gcd,rt.gcd);
    if(nd.gcd == lt.gcd) nd.cn+=lt.cn;
    if(nd.gcd == rt.gcd) nd.cn += rt.cn;

    return nd;

}
void push_up(int x){
    t[x]=combine(t[lson],t[rson]);
}
void build(int x, int l, int r){
    if(l==r){
        cin>>t[x].gcd;
        t[x].cn=1;
        return;
    }

    build(lson,l,mid);
    build(rson,mid+1,r);

    push_up(x);
}

struct data dummy;
data query(int x, int l, int r, int const L, int const R){
    if(l<=L && r>= R) return t[x];
    if(R<l || L>r) return dummy;

    return combine(query(lson,l,mid,L,R) , query(rson,mid+1,r,L,R));

}

data query2(int L,int R,int l,int r,int rt);

int main(){

    cin>>n;
    build(1,1,n);

    int NQuery;
    cin>>NQuery;
    for(int i=0;i<NQuery;i++){
        int l,r;
        cin>>l>>r;
        l--;
        r--;

      // struct data temp=query(1,0,n-1,l,r);
       struct data temp=query2(l,r,1,n,1);

        cout<<"temp.cn: "<<temp.cn<<endl;
        int ans= (r-l+1 - temp.cn);
        cout<<"ans: "<<ans<<endl;

    }

    return 0;
}
/*
int findGCD(int a, int b){
    if (a == 0)
        return b;
    return findGCD(b%a, a);
}
*/
int findGCD(int a,int b){
int r=a%b;
while(r){
a=b;
b=r;
r=a%b;
}return b;
}

data query2(int L,int R,int x,int r,int rt)
{
    if(L==x&&R==r)
    {
        return t[rt];
    }
    int mid1=(x+r)/2;
    if(R<=mid1)return query2(L,R,lson,r,rt);
    else if(L>mid1)return query2(L,R,rson,r,rt);
    else return combine(query2(L,mid1,lson,r,rt),query2(mid1+1,R,rson,r,rt));
}


#include <cstdio>
#define lson (x<<1)
#define rson (x<<1|1)
#define mid ((l+r)>>1)
using namespace std;
const int N=(1<<17)+10;
int n,m,a[N<<2];
bool floor[N<<2];
void push_up(int x){
    floor[x]=!floor[lson];
    if(floor[x])a[x]=a[lson]|a[rson];
    else a[x]=a[lson]^a[rson];
}
void build(int x,int l,int r){
    if(l==r){
        scanf("%d",&a[x]);
        floor[x]=0;
        return;
    }
    build(lson,l,mid);
    build(rson,mid+1,r);
    push_up(x);
}
void update(int x,int l,int r,int p,int b){
    if(l==p&&p==r){
        a[x]=b;
        return;
    }
    if(p<=mid)update(lson,l,mid,p,b);
    else update(rson,mid+1,r,p,b);
    push_up(x);
}
int query(int x,int l,int r){
    return a[x];
}
int main(void){
    scanf("%d%d",&n,&m);
    build(1,1,1<<n);
    while(m--){
        int p,b,ans;
        scanf("%d%d",&p,&b);
        update(1,1,1<<n,p,b);
        ans=query(1,1,1<<n);
        printf("%d\n",ans);
    }
}


// Aditya Jain

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

typedef long long int lld;
typedef long double ldb;

#define pb push_back
#define mp make_pair

lld tree[1<<20];
void update(bool mode, lld node, lld start, lld end, lld val, lld idx){
	if(idx < start || idx > end) return;
	if(start==end){
		tree[node]=val;
		return;
	}

	lld mid = (start + end)/2;
	update(mode^1,2*node, start, mid, val, idx);
	update(mode^1,2*node + 1, mid + 1, end, val, idx);
	if(mode) tree[node] = tree[2*node] | tree[2*node+1];
	else tree[node] = tree[2*node] ^ tree[2*node+1];
}

int main(){
	lld n, m, ix, value;
	cin >> n >> m;
	lld A[n];
	for(lld i=0;i<(1<<n);i++){
		scanf("%lld", A+i);
		update(n%2,1,0,(1<<n)-1,A[i],i);
	}
	while(m--){
		cin >> ix >> value;
		ix--;
		A[ix]=value;
		update(n%2,1,0,(1<<n)-1,value,ix);
		printf("%lld ",tree[1]);

	}
	return 0;
}


// Aditya Jain

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

typedef long long int lld;
typedef long double ldb;

#define pb push_back
#define mp make_pair

lld tree[1<<20];
void update(bool mode, lld node, lld start, lld end, lld val, lld idx){
	if(idx < start || idx > end) return;
	if(start==end){
		tree[node]=val;
		return;
	}

	lld mid = (start + end)/2;
	update(mode^1,2*node, start, mid, val, idx);
	update(mode^1,2*node + 1, mid + 1, end, val, idx);
	if(mode) tree[node] = tree[2*node] | tree[2*node+1];
	else tree[node] = tree[2*node] ^ tree[2*node+1];
}

int main(){
	lld n, m, ix, value;
	cin >> n >> m;
	lld A[n];
	for(lld i=0;i<(1<<n);i++){
		scanf("%lld", A+i);
		update(n%2,1,0,(1<<n)-1,A[i],i);
	}
	while(m--){
		scanf("%lld%lld", &ix, &val);
		ix--;
		A[ix]=value;
		update(n%2,1,0,(1<<n)-1,value,ix);
		printf("%lld ",tree[1]);

	}
	return 0;
}


// Aditya Jain

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

typedef long long int lld;
typedef long double ldb;

#define pb push_back
#define mp make_pair

lld tree[1<<20];
void update(bool mode, lld node, lld start, lld end, lld val, lld idx){
	if(idx < start || idx > end) return;
	if(start==end){
		tree[node]=val;
		return;
	}

	lld mid = (start + end)/2;
	update(mode^1,2*node, start, mid, val, idx);
	update(mode^1,2*node + 1, mid + 1, end, val, idx);
	if(mode) tree[node] = tree[2*node] | tree[2*node+1];
	else tree[node] = tree[2*node] ^ tree[2*node+1];
}

int main(){
	lld n, m, ix, value;
	cin >> n >> m;
	lld A[n];
	for(lld i=0;i<(1<<n);i++){
		cin >> A[i];
		update(n%2,1,0,(1<<n)-1,A[i],i);
	}
	while(m--){
		cin >> ix >> value;
		ix--;
		A[ix]=value;
		update(n%2,1,0,(1<<n)-1,value,ix);
		cout << tree[1] << endl;

	}
	return 0;
}


// Aditya Jain

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

typedef long long int lld;
typedef long double ldb;

#define pb push_back
#define mp make_pair

lld tree[1<<20];
void update(bool mode, lld node, lld start, lld end, lld val, lld idx){
	if(idx < start || idx > end) return;
	if(start==end){
		tree[node]=val;
		return;
	}

	lld mid = (start + end)/2;
	update(mode^1,2*node, start, mid, val, idx);
	update(mode^1,2*node + 1, mid + 1, end, val, idx);
	if(mode) tree[node] = tree[2*node] | tree[2*node+1];
	else tree[node] = tree[2*node] ^ tree[2*node+1];
}

int main(){
	lld n, m, ix, value;
	cin >> n >> m;
	lld A[n];
	for(lld i=0;i<(1<<n);i++){
		scanf("%lld", A+i);
		update(n%2,1,0,(1<<n)-1,A[i],i);
	}
	while(m--){
		scanf("%lld%lld", &ix, &value);
		ix--;
		A[ix]=value;
		update(n%2,1,0,(1<<n)-1,value,ix);
		printf("%lld ",tree[1]);

	}
	return 0;
}


// Aditya Jain

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

typedef long long int lld;
typedef long double ldb;

#define pb push_back
#define mp make_pair

int tree[1<<20];
void update(bool mode, int node, int start, int end, int val, int idx){
	if(idx < start || idx > end) return;
	if(start==end){
		tree[node]=val;
		return;
	}

	int mid = (start + end)/2;
	update(mode^1,2*node, start, mid, val, idx);
	update(mode^1,2*node + 1, mid + 1, end, val, idx);
	if(mode) tree[node] = tree[2*node] | tree[2*node+1];
	else tree[node] = tree[2*node] ^ tree[2*node+1];
}

int main(){
	int n, m, ix,x, value;
	cin >> n >> m;
	for(int i=0;i<(1<<n);i++){
		scanf("%d", x);
		update(n%2,1,0,(1<<n)-1,x,i);
	}
	while(m--){
		scanf("%d%d", &ix, &value);
		ix--;
		update(n&1,1,0,(1<<n)-1,value,ix);
		printf("%d\n",tree[1]);

	}
	return 0;
}


// Aditya Jain

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

typedef long long int lld;
typedef long double ldb;

#define pb push_back
#define mp make_pair

int tree[1<<20];
void update(bool mode, int node, int start, int end, int val, int idx){
	if(idx < start || idx > end) return;
	if(start==end){
		tree[node]=val;
		return;
	}

	int mid = (start + end)/2;
	update(mode^1,2*node, start, mid, val, idx);
	update(mode^1,2*node + 1, mid + 1, end, val, idx);
	if(mode) tree[node] = tree[2*node] | tree[2*node+1];
	else tree[node] = tree[2*node] ^ tree[2*node+1];
}

int main(){
	int n, m, ix, value;
	cin >> n >> m;
	int A[n];
	for(int i=0;i<(1<<n);i++){
		scanf("%d", A+i);
		update(n%2,1,0,(1<<n)-1,A[i],i);
	}
	while(m--){
		scanf("%d%d", &ix, &value);
		ix--;
		A[ix]=value;
		update(n&1,1,0,(1<<n)-1,value,ix);
		printf("%d\n",tree[1]);

	}
	return 0;
}


// Aditya Jain

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

typedef long long int lld;
typedef long double ldb;

#define pb push_back
#define mp make_pair

int tree[1<<20];
void update(bool mode, int node, int start, int end, int val, int idx){
	if(idx < start || idx > end) return;
	if(start==end){
		tree[node]=val;
		return;
	}

	int mid = (start + end)/2;
	update(mode^1,2*node, start, mid, val, idx);
	update(mode^1,2*node + 1, mid + 1, end, val, idx);
	if(mode) tree[node] = tree[2*node] | tree[2*node+1];
	else tree[node] = tree[2*node] ^ tree[2*node+1];
}

int main(){
	int n, m, ix,x, value;
	cin >> n >> m;
	for(int i=0;i<(1<<n);i++){
		scanf("%d", &x);
		update(n%2,1,0,(1<<n)-1,x,i);
	}
	while(m--){
		scanf("%d%d", &ix, &value);
		ix--;
		update(n&1,1,0,(1<<n)-1,value,ix);
		printf("%d\n",tree[1]);

	}
	return 0;
}


// Aditya Jain

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

typedef long long int lld;
typedef long double ldb;

#define pb push_back
#define mp make_pair

lld tree[1<<20];
void update(bool mode, lld node, lld start, lld end, lld val, lld idx){
	if(idx < start || idx > end) return;
	if(start==end){
		tree[node]=val;
		return;
	}

	lld mid = (start + end)/2;
	update(mode^1,2*node, start, mid, val, idx);
	update(mode^1,2*node + 1, mid + 1, end, val, idx);
	if(mode) tree[node] = tree[2*node] | tree[2*node+1];
	else tree[node] = tree[2*node] ^ tree[2*node+1];
}

int main(){
	lld n, m, ix, value;
	cin >> n >> m;
	lld A[n];
	for(lld i=0;i<(1<<n);i++){
		scanf("%lld", A+i);
		update(n%2,1,0,(1<<n)-1,A[i],i);
	}
	while(m--){
		scanf("%lld%lld", &ix, &value);
		ix--;
		A[ix]=value;
		update(n%2,1,0,(1<<n)-1,value,ix);
		printf("%lld\n",tree[1]);

	}
	return 0;
}