#include #include #include using namespace std; using ll = long long; ll check(ll x, int q, const vector &a){ vector stack; for (int i = 0; i < q; i++){ if (a[i] == "X"){ stack.emplace_back(x); } else if (a[i] == "+"){ assert(stack.size() > 1); auto r = stack.back(); stack.pop_back(); auto t = stack.back(); stack.pop_back(); stack.emplace_back(t + r); } else if (a[i] == "min"){ assert(stack.size() > 1); auto r = stack.back(); stack.pop_back(); auto t = stack.back(); stack.pop_back(); stack.emplace_back(min(t, r)); } else if (a[i] == "max"){ assert(stack.size() > 1); auto r = stack.back(); stack.pop_back(); auto t = stack.back(); stack.pop_back(); stack.emplace_back(max(t, r)); } else{ stack.emplace_back(stol(a[i])); } } assert(stack.size() == 1); return stack[0]; } int main(){ int q; ll y; cin >> q >> y; vector a(q); for(auto &i: a) cin >> i; ll mn = -1, mx = y + 100; while(mx - mn > 1){ ll md = (mx + mn) / 2ll; if(check(md, q, a) < y) mn = md; else mx = md; } if (check(mx, q, a) == y) cout << mx << endl; else cout << -1 << endl; }