Q, Y = map(int, input().split()) S = list(map(str, input().split())) def solve(S, x): stack = [] for i in S: if i == "X" or (i != "max" and i != "min" and i != "+"): if i == "X": stack.append(x) else: stack.append(i) else: p = stack.pop() q = stack.pop() if i == "+": stack.append(int(p) + int(q)) else: if i == "max": stack.append(max(int(p), int(q))) else: stack.append(min(int(p), int(q))) return stack[-1] if "X" not in S: if int(solve(S, 0)) == Y: print(0) else: print(-1) exit() left = -1 right = 10 ** 14 while left + 1 < right: mid = (left + right) // 2 res = int(solve(S, mid)) if res == Y: right = mid elif res < Y: left = mid else: right = mid if solve(S, right) == Y: print(right) else: print(-1)