#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define dep(i,a,b) for(int i=(a);i>=(b);i--)
#define VV vector<int>
#define PP pair<int,int>
#define ls (rt<<1)
#define rs (rt<<1|1)
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
template <typename T>
inline void read(T &X){
    X=0;int w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    if(w) X=-X;
}
const int maxn=1e5+5;
//const double pi=acos(-1.0);
//const double eps=1e-9;
//const ll mo=1e9+7;
int n,m,k;
int a[maxn],stk[maxn],ok[maxn],ru[maxn];
int ans,tmp,cnt;
int flag;
map<int, ll> dp[maxn];
multiset<ll> st[maxn];
ll sum[maxn];
char s[maxn];
void solve(){
    read(n);
    read(k);
    cnt = 0;
    st[cnt].insert(0);
    dp[cnt][0] = 0;
    sum[cnt] = 0;
    rep(i,1,n){
        scanf("%s", s);
        if(s[0]=='s'){
            int x, v;
            read(x);
            read(v);
            if(ok[cnt])
                continue;
            sum[cnt] += v;
            //cout << "debug: " << i << " " << cnt << " " << x << endl;
            if(x==k)
                continue;
            if(!dp[cnt].count(x)){
                dp[cnt][x] = *st[cnt].begin() - v;
                st[cnt].insert(dp[cnt][x]);
                //cout << "debug; " << cnt << " " << x <<" "<< dp[cnt][x] << endl;
            }
            else {
                ll nv = *st[cnt].begin() - v;
                auto it = st[cnt].find(dp[cnt][x]);
                st[cnt].erase(it);
                dp[cnt][x] = nv;
                st[cnt].insert(nv);
            }
        }
        else if(s[0]=='i'){
            int x;
            read(x);
            cnt++;
            if(!dp[cnt-1].count(x))
                ok[cnt] = 1;
            if(!ok[cnt]){
                ru[cnt] = x;
                sum[cnt] = 0;
                dp[cnt].clear();
                st[cnt].clear();
                dp[cnt][x] = dp[cnt - 1][x] + sum[cnt - 1];
                st[cnt].insert(dp[cnt][x]);
                //cout << "debug: " << x << " " << dp[cnt][x] << endl;
            }
        }
        else {
            if(ok[cnt]){
                ok[cnt] = 0;
                sum[cnt] = 0;
                cnt--;
                continue;
            }
            int fg = 0;
            if(dp[cnt].size()>dp[cnt-1].size()){
                swap(dp[cnt], dp[cnt - 1]);
                swap(sum[cnt], sum[cnt - 1]);
                swap(st[cnt], st[cnt - 1]);
                //swap(ru[cnt], ru[cnt - 1]);
                fg = 1;
            }
            for(auto x:dp[cnt]){
                ll v = x.first;
                ll cost = x.second + sum[cnt] - sum[cnt - 1];
                //cout << "!!: "<<cnt<<" " << v << " " <<x.second<<" "<<sum[cnt]<< " "<<sum[cnt-1]<<" "<<cost << endl;
                if(!dp[cnt-1].count(v)){
                    dp[cnt - 1][v] = cost;
                    st[cnt - 1].insert(dp[cnt - 1][v]);
                }
                else if (ru[cnt]==v||(cost < dp[cnt - 1][v])){
                    if(fg&&ru[cnt]==v)
                        continue;
                    auto it = st[cnt - 1].find(dp[cnt - 1][v]);
                    st[cnt - 1].erase(it);
                    dp[cnt - 1][v] = cost;
                    st[cnt - 1].insert(cost);
                }
            }
            //sum[cnt - 1] += sum[cnt];
            cnt--;
        }
    }
    /*
    for(auto x:dp[0]){
        cout << "debug: " << x.first << " " << x.second << endl;
    }*/
    //auto it = st[0].find(dp[0][0]);
    //st[0].erase(it);
    auto it = st[0].begin();
    printf("%lld\n", (*it) + sum[0]);
}
int main(){
    // freopen("e://duipai//amyout.txt","w",stdout);
    int T=1,cas=1;
    //read(T);
    while(T--){
        solve();
    }
    //system("pause");
    return 0;
}
