从高位往地位贪心即可
# include <bits/stdc++.h>
# define IL inline
# define RG register
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
const int _(1e5 + 10);IL ll Read(){RG char c = getchar(); RG ll x = 0, z = 1;for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);return x * z;
}int n, m, ans, t[_], op[_];int main(RG int argc, RG char* argv[]){n = Read(); m = Read();for(RG int i = 1; i <= n; i++){RG char c; scanf(" %c", &c); t[i] = Read();if(c == 'A') op[i] = 1;else if(c == 'O') op[i] = 2;else op[i] = 3;}for(RG int l = 30; l >= 0; l--){RG int cnt1 = 1, cnt2 = 0;for(RG int i = 1; i <= n; i++){RG int d = (t[i] >> l) & 1;if(op[i] == 1) cnt1 &= d, cnt2 &= d;else if(op[i] == 2) cnt1 |= d, cnt2 |= d;else cnt1 ^= d, cnt2 ^= d;}if(cnt2) ans += 1 << l;else if(cnt1 && m >= (1 << l)) ans += 1 << l, m -= 1 << l;}printf("%d\n", ans);return 0;
}