Q,Y=map(int,input().split()) S=input().split() def calc(x): ANS=[] for s in S: if s=="X": ANS.append(x) elif s=="+": k=ANS.pop() l=ANS.pop() ANS.append(k+l) elif s=="max": k=ANS.pop() l=ANS.pop() ANS.append(max(k,l)) elif s=="min": k=ANS.pop() l=ANS.pop() ANS.append(min(k,l)) else: u=int(s) ANS.append(u) return ANS[-1] if calc(0)==Y: print(0) exit() elif calc(0)>Y: print(-1) exit() OK=0 NG=10**18 while NG>OK+1: mid=(OK+NG)//2 if calc(mid)