#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ls (p<<1)
#define rs (p<<1|1)
#define mid ((l+r)>>1)
#define lb(x) (x&-x)
const int maxn=100010;
const int mo=1000000007;
const int inf=0x7f7f7f7f7f7f7f7f;
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=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
int n,m,t[maxn],ans,ans0,cnt0,cnt1=-1;
string op[maxn];
signed main(){
n=read();
m=read();
for(int i=1;i<=n;i++){
cin>>op[i];
t[i]=read();
if(op[i][0]=='A'){
cnt0&=t[i];
cnt1&=t[i];
}
else if(op[i][0]=='O'){
cnt0|=t[i];
cnt1|=t[i];
}
else{
cnt0^=t[i];
cnt1^=t[i];
}
}
int is=1;
for(int i=50;i>=0;i--){
bool c0=(cnt0>>i)&1,c1=(cnt1>>i)&1,lim=(m>>i)&1;
if(c0|(c1&lim)|(c1&(!is)))
ans+=1ll<<i;
if(c0&lim)
is=0;
}
printf("%lld\n",ans);
return 0;
}