#include using namespace std; using ll = long long; #define rep(i, s, e) for (int i = (int)s; i < (int)e; ++i) #define all(a) (a).begin(), (a).end() ll culc(ll X,ll N, vector &s, vector &num) { stack st; rep(i, 0, N) { if (s[i] == "X") { st.push(X); continue; } if (num[i] != -1) { st.push(num[i]); continue; } ll top = st.top(); st.pop(); if (s[i] == "max") st.top() = max(st.top(), top); else if (s[i] == "min") st.top() = min(st.top(), top); else st.top() = st.top() + top; } return st.top(); } int main() { cin.tie(nullptr); ll Q, Y; cin >> Q >> Y; vector s(Q); vector num(Q, -1); rep(i, 0, Q) { cin >> s[i]; if (s[i] != "min" && s[i] != "max" && s[i] != "+" && s[i] != "X") { num[i] = stoi(s[i]); } } ll ng = -1, ok = LLONG_MAX - 10; while (ok - ng > 1) { ll mid = (ok - ng) / 2 + ng; if (culc(mid, Q, s, num) >= Y) ok = mid; else ng = mid; } if (culc(ok, Q, s, num) == Y) cout << ok << '\n'; else cout << -1 << '\n'; }