#include <bits/stdc++.h> using namespace std; #include <atcoder/all> using namespace atcoder; template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); } template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); } #define rep(i, n) for (long long i = 0; i < (long long)(n); i++) #define rep2(i, m ,n) for (int i = (m); i < (long long)(n); i++) #define REP(i, n) for (long long i = 1; i < (long long)(n); i++) typedef long long ll; #define updiv(N,X) (N + X - 1) / X #define l(n) n.begin(),n.end() #define YesNo(Q) Q==1?cout<<"Yes":cout<<"No" using P = pair<int, int>; using mint = modint; const int MOD = 998244353LL; const ll INF = 999999999999LL; vector<long long> fact, fact_inv, inv; /* init_nCk :二項係数のための前処理 計算量:O(n) */ template <typename T> void input(vector<T> &v){ rep(i,v.size()){cin>>v[i];} return; } void init_nCk(int SIZE) { fact.resize(SIZE + 5); fact_inv.resize(SIZE + 5); inv.resize(SIZE + 5); fact[0] = fact[1] = 1; fact_inv[0] = fact_inv[1] = 1; inv[1] = 1; for (int i = 2; i < SIZE + 5; i++) { fact[i] = fact[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD; } } /* nCk :MODでの二項係数を求める(前処理 int_nCk が必要) 計算量:O(1) */ long long nCk(int n, int k) { assert(!(n < k)); assert(!(n < 0 || k < 0)); return fact[n] * (fact_inv[k] * fact_inv[n - k] % MOD) % MOD; } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } ll POW(ll a,ll n){ long long res = 1; while (n > 0) { if (n & 1) res = res * a; a = a * a; n >>= 1; } return res; } ll q,y; vector<string> v; void otp(stack<ll> st){ ll nn = st.size(); rep(i,nn){ cout << st.top() << endl; st.pop(); } } ll ev(ll t){ stack<ll> st; rep(i,q){ // otp(st); if(v[i]=="+"){ ll a = st.top();st.pop(); ll b = st.top();st.pop(); st.push(a+b); } else if(v[i]=="min"){ ll a = st.top();st.pop(); ll b = st.top();st.pop(); st.push(min(a,b)); } else if(v[i]=="max"){ ll a = st.top();st.pop(); ll b = st.top();st.pop(); st.push(max(a,b)); } else if(v[i]=="X"){ st.push(t); } else{ st.push(stol(v[i])); } } return st.top(); } int main() { cin>>q>>y; v.resize(q); rep(i,q){cin>>v[i];} ll mn = -1;ll mx = 99999999999999LL; while(1<mx-mn){ ll mid = (mx+mn)/2; ll t = ev(mid); if(y<=t){mx = mid;} else{mn = mid;} } if(99999999999999LL<=mx){cout<<-1<<endl;} else if(ev(mx)!=y){cout<<-1<<endl;} else{cout << mx << endl;} }