#include<bits/stdc++.h>usingnamespace std;int n, m;constint N =1e5+10;int a[N], opt[N];boolcalc(bool x,int y){for(int i =0; i < n; i ++)if(opt[i]==1)
x |= a[i]>> y &1;elseif(opt[i]==2)
x &= a[i]>> y &1;else
x ^= a[i]>> y &1;return x;}signedmain(){
cin >> n >> m;for(int i =0; i < n; i ++){
string s;
cin >> s;
cin >> a[i];if(s =="OR")
opt[i]=1;elseif(s =="AND")
opt[i]=2;else
opt[i]=3;}int ans =0;for(int i =29;~i; i --)if((1<< i)<= m){bool _1 =calc(0, i), _2 =calc(1, i);if(_1 >= _2)
ans |= _1 << i;else
ans |= _2 << i, m -=1<< i;}else
ans |=calc(0, i)<< i;
cout << ans <<'\n';return0;}