#include using namespace std; // #include // using namespace atcoder; #define overload4(_1, _2, _3, _4, name, ...) name // 1~4個目を無視 #define rep1(n) for(ll i = 0; i < (ll)(n); ++i) #define rep2(i, n) for(ll i = 0; i < (ll)(n); ++i) #define rep3(i, a, b) for(ll i = (a); i < (ll)(b); ++i) #define rep4(i, a, b, c) for(ll i = (a); i < (ll)(b); i += (ll)(c)) #define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__) #define all(x) x.begin(), x.end() using ll = long long; using pll = pair; template using pq = priority_queue, greater>; const int INF = 1 << 29; const ll LINF = 0x1fffffffffffffff; template auto make_vec(const size_t (&d)[n], const T& init) noexcept { if constexpr (idx < n) return std::vector(d[idx], make_vec(d, init)); else return init; } template auto make_vec(const size_t (&d)[n]) noexcept { return make_vec(d, T{}); } struct Edge{ Edge(ll t, ll c): to(t), cost(c) {}; ll to; ll cost; }; //====================================================================================================== ll Q, Y; vector s; ll func(ll y){ stack st; rep(i, Q){ if ('0' <= s[i][0] && s[i][0] <= '9'){ st.push(s[i]); } else if (s[i] == "X"){ st.push(to_string(y)); } else if (s[i] == "+"){ auto l = st.top(); st.pop(); auto r = st.top(); st.pop(); ll v = stoll(l) + stoll(r); st.push(to_string(v)); } else if (s[i] == "max"){ auto l = st.top(); st.pop(); auto r = st.top(); st.pop(); ll v = max(stoll(l), stoll(r)); st.push(to_string(v)); } else if (s[i] == "min"){ auto l = st.top(); st.pop(); auto r = st.top(); st.pop(); ll v = min(stoll(l), stoll(r)); st.push(to_string(v)); } } ll val = stoll(st.top()); return val; } int main(){ cin >> Q >> Y; rep(i, Q) { string ss; cin >> ss; s.push_back(ss); } ll ok = 10000000000010; ll ng = -1; while (ok - ng > 1){ ll mid = (ok + ng) / 2; if (func(mid) >= Y) ok = mid; else ng = mid; } if (func(ok) != Y) { cout << -1 << endl; } else{ cout << ok << endl; } }