Q, Y = map(int, input().split()) S = list(map(str, input().split())) stack = [] for i in S: if i == "X" or (i != "max" and i != "min" and i != "+"): stack.append(i) else: p = stack.pop() q = stack.pop() if i == "+": stack.append(p + i + q) else: stack.append(i + "(" + p + "," + q + ")") que = stack[-1] left = -1 right = 10 ** 9 + 1 while left + 1 < right: mid = (left + right) // 2 que2 = que.replace("X", str(mid)) if eval(que2) == Y: right = mid elif eval(que2) < Y: left = mid else: right = mid if eval(que.replace("X", str(right))) == Y: print(right) else: print(-1)