Q, Y = map(int, input().split()) S = list(input().split()) def f(x): stack = [] for s in S: if s == "+": a = stack.pop() b = stack.pop() stack.append(a+b) elif s == "max": a = stack.pop() b = stack.pop() stack.append(max(a,b)) elif s == "min": a = stack.pop() b = stack.pop() stack.append(min(a,b)) elif s == "X": stack.append(x) else: stack.append(int(s)) return stack[-1] def BinarySearch(yes = 10 ** 18, no = -1): while abs(yes - no) != 1: mid = (yes + no)//2 if f(mid) >= Y: yes = mid else: no = mid return yes ans = BinarySearch() print(ans) if ans <= 10 ** 15 and f(ans) == Y else print(-1)