# 读取输入
n, m = map(int, input().split())
doors = []
# 记录防御门的操作和参数
for _ in range(n):
op, t = input().split()
doors.append((op, int(t)))
# 初始化最大攻击力
attack = 0
result = 0
def check(result):
for op, t in doors:
if op == "AND":
result &= t
elif op == "OR":
result |= t
elif op == "XOR":
result ^= t
return result
if n == 0:
print(m)
exit(0)
# 从高位到低位尝试
for bit in range(m.bit_length() - 1, -1, -1):
# 当前位假设为 1
temp_attack = attack | (1 << bit)
if temp_attack > m:
continue
temp_result = check(temp_attack)
# 如果假设的当前位为 1 不超过 `m` 且使结果更优,保留该位
if temp_result >= result:
attack += temp_attack
# 模拟一次完整攻击后的结果
result = check(attack)
# 输出结果
print(result)