#include using namespace std; using ll = long long; int main(){ ll Q, Y; cin >> Q >> Y; vector S(Q); for (int i = 0; i < Q; i++) { cin >> S[i]; } auto rpn = [&](ll x) -> ll { 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(stoi(s)); } } } return A.top(); }; ll ok = (ll)1e14; ll ng = -1LL; while (ok - ng > 1) { ll mid = (ok + ng) / 2; if (rpn(mid) >= Y) { ok = mid; } else { ng = mid; } } cout << (rpn(ok) == Y ? ok : -1) << endl; return 0; }