Y=int(input().split()[1]) S=input().split() def f(x): A=[] for s in S: if"0">s:a=A.pop();A[-1]+=a elif"m">s:A+=[int(s)if"X">s else x] else:A[-2]=[min,max]["mi">s](A[-2:]);A.pop() return A[0] l,r=0,Y+1 while l+1>1 if f(m)>Y:r=m else:l=m print([l,-1][f(l)