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] for i in range(5 * 10 ** 5): que2 = que.replace("X", str(i)) if eval(que2) == Y: print(i) exit() print(-1)