Q, Y = map(int,input().split()) S = input().split() code = {"+":0,"min":1,"max":2} def f(x): stack = [] for s in S: if s.isdigit(): stack.append(int(s)) elif s == "X": stack.append(x) else: a = stack.pop() b = stack.pop() match code[s]: case 0: stack.append(a + b) case 1: stack.append(min(a,b)) case 2: stack.append(max(a,b)) dum = 0 return stack[0] lb = -1 ub = Y while ub - lb > 1: mid = (ub + lb) // 2 if f(mid) >= Y: ub = mid else: lb = mid if f(ub) == Y: print(ub) else: print(-1)