q, y = map(int, input().split()) s = input().split() l = -1 r = y + 2 def solve(x): stack = [] for i in range(q): if s[i] == "X": stack.append(x) elif s[i] == "+": a = stack.pop() b = stack.pop() stack.append(a + b) elif s[i] == "min": a = stack.pop() b = stack.pop() stack.append(min(a, b)) elif s[i] == "max": a = stack.pop() b = stack.pop() stack.append(max(a, b)) else: stack.append(int(s[i])) return stack[0] while r-l > 1: x = (l + r) >> 1 if solve(x) >= y: r = x else: l = x if solve(r) == y: print(r) else: print(-1)