#include using namespace std; using ll = long long; ll rev_polish(vector &S, ll x) { stack A; for (string s : S) { if (s == "+" || s == "min" || s == "max") { ll a = A.top(); A.pop(); ll b = A.top(); A.pop(); if (s == "+") { A.push(a + b); } else if (s == "min") { A.push(min(a, b)); } else { A.push(max(a, b)); } } else { if (s == "X") { A.push(x); } else { A.push(stoll(s)); } } } return A.top(); } int main() { ll Q, Y; cin >> Q >> Y; vector S(Q); for (int i = 0; i < Q; i++) { cin >> S[i]; } ll ok = Y; ll ng = -1; while (ok - ng > 1) { ll mid = (ok + ng) / 2; if (rev_polish(S, mid) >= Y) { ok = mid; } else { ng = mid; } } if (rev_polish(S, ok) == Y) { cout << ok << endl; } else { cout << -1 << endl; } return 0; }