q,t = map(int,input().split()) s = list(input().split()) l,r = 0,10**18 for i in range(70): mid = (l+r)//2 st = [] for j in s: if j == '+': x = st.pop() y = st.pop() st.append(x+y) elif j == 'max': x = st.pop() y = st.pop() st.append(max(x,y)) elif j == 'min': x = st.pop() y = st.pop() st.append(min(x,y)) elif j == 'X': st.append(mid) else: st.append(int(j)) if st[0] < t: l = mid else: r = mid #print(l,r,st[0]) if i != 69: continue mid = r st = [] for j in s: if j == '+': x = st.pop() y = st.pop() st.append(x+y) elif j == 'max': x = st.pop() y = st.pop() st.append(max(x,y)) elif j == 'min': x = st.pop() y = st.pop() st.append(min(x,y)) elif j == 'X': st.append(mid) else: st.append(int(j)) if st[0] == t: print(r) else: print(-1)