Q, Y = (int(x) for x in input().split()) s = list(map(str, input().split())) def calc(x): stack = [] for j in s: if j == "X": stack.append(x) elif j == "+": a = stack.pop() b = stack.pop() stack.append(a+b) elif j == "max": a = stack.pop() b = stack.pop() stack.append(max(a, b)) elif j == "min": a = stack.pop() b = stack.pop() stack.append(min(a, b)) else: stack.append(int(j)) return stack[-1] left, right = -1, 10**20 while left + 1 < right: mid = (left+right)//2 if calc(mid) < Y: left = mid else: right = mid if calc(right) == Y: print(right) else: print(-1)