import sys, math sys.setrecursionlimit(10**7) from itertools import * from heapq import heapify, heappush, heappop from collections import deque, defaultdict, Counter from bisect import bisect_left, bisect_right from copy import copy, deepcopy # from sortedcontainers import SortedSet, SortedList, SortedDict INF, LINF, ipt = float('inf'), 1 << 60, sys.stdin.readline iin, mii = lambda: int(ipt()), lambda: map(int, ipt().split()) lmi = lambda: list(map(int, ipt().split())) Q, Y = mii() s = input().split() def solve(x): """f(x) >= Y""" st = deque() for i in range(Q): if s[i].isdigit(): st.append(int(s[i])) elif s[i] == "X": st.append(x) elif s[i] == "+": a = st.pop() b = st.pop() st.append(a + b) elif s[i] == "min": a = st.pop() b = st.pop() st.append(min(a, b)) elif s[i] == "max": a = st.pop() b = st.pop() st.append(max(a, b)) return st.pop() ok = 10**13 + 10 ng = -1 while ok - ng > 1: mid = (ok + ng) // 2 if solve(mid) >= Y: ok = mid else: ng = mid if solve(ok) == Y: print(ok) else: print(-1)