#include #define For(i, a, b) for(long long i = a; i < b; i++) #define rep(i, n) For(i, 0, n) #define rFor(i, a, b) for(long long i = a; i >= b; i--) #define ALL(v) (v).begin(), (v).end() #define rALL(v) (v).rbegin(), (v).rend() using namespace std; using lint = long long; using ld = long double; int INF = 2000000000; lint LINF = 1000000000000000000; int main() { int q; lint y; cin >> q >> y; vector s(q); rep(i, q) { cin >> s[i]; } auto f = [&](lint x) { vector a; rep(i, q) { int sz = a.size(); if (s[i] == "+") { a[sz - 2] = a[sz - 2] + a[sz - 1]; a.pop_back(); } else if (s[i] == "max") { a[sz - 2] = max(a[sz - 2], a[sz - 1]); a.pop_back(); } else if (s[i] == "min") { a[sz - 2] = min(a[sz - 2], a[sz - 1]); a.pop_back(); } else { a.emplace_back(s[i] == "X" ? x : stoll(s[i])); } } return a[0]; }; if (f(0LL) == y) { cout << 0 << endl; return 0; } lint l = 0, r = LINF; while (r - l > 1) { lint mid = (l + r) / 2; if (f(mid) >= y) { r = mid; } else { l = mid; } } cout << (f(r) == y ? r : -1) << endl; }