N,Y = map(int,input().split()) S = list(input().split()) Op = ["+","min","max"] def f(x): A = [] for i in range(N): if S[i] not in Op: if S[i]=="X": A.append(x) else: A.append(int(S[i])) else: a = A.pop() b = A.pop() if S[i]=="+": A.append(a+b) elif S[i]=="min": A.append(min(a,b)) else: A.append(max(a,b)) return A[0] low = -1 high = 10**13+10 while high-low>1: mid = (high+low)//2 if f(mid)>=Y: high = mid else: low = mid x = high if f(x)==Y: print(x) else: print(-1)