Q,Y = map(int,input().split()) S = input().split() inf = 1<<60 ok = inf ng = -1 ans = None while ok-ng > 1: X = (ok+ng)//2 A = [] for s in S: if s.isdecimal(): A.append(int(s)) elif s == "X": A.append(X) elif s == "+": A[-2] += A[-1] A.pop() elif s == "min": A[-2] = min(A[-2],A[-1]) A.pop() elif s == "max": A[-2] = max(A[-2],A[-1]) A.pop() if A[0] >= Y: ok = X ans = A[0] else: ng = X if abs(ok) == inf: print(-1) else: if ans == Y: print(ok) else: print(-1)