#include<iostream>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<iomanip>
#include<stack>
#include<cmath>

 
using namespace std;
 
 
#ifndef POJ
    #define Cpp11
#endif
 
#ifdef Cpp11
    #define _for(i,a,b) for(auto i = (a);i<(b);++i)
    #define _rep(i,a,b) for(auto i = (a);i<=(b);++i)
    #define _dep(i,a,b) for(auto i = (a);i>=(b);--i)
    #define mt(a,b,c) make_tuple(a,b,c) 
    #include<ctime>
    #include<random>
    #include<chrono>
    #include<limits>
    #include<complex>
    #include<unordered_set>
    #include<unordered_map>
    #include<cassert>
    #include<functional>
    #include<bitset>
    #define IO ios::sync_with_stdio(false);cout.tie(nullptr);cin.tie(nullptr);
#endif
 
#ifndef Cpp11
    #define _for(i,a,b) for(int i = (a);i<(b);++i)
    #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 IO ios::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
#endif
 
 
using namespace std;


 
#define fr first
#define sc second
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define sci(x) scanf("%d",&(x))
#define scl(x) scanf("%lld",&(x))
#define debugline fprintf(stderr,"-----------------------\n");
#define szint(x) ((int)(x).size())

 
#ifdef I128IO
typedef __int128 SPLL;
char buff[200];
template<typename T>
void read(T& o)
{
    o = 0;
    scanf("%s",buff);
    //printf("%s\n",buff);
    T f = 1;
    int i = 0;
 
    if(buff[0]=='-')i++,f = -1;
    for(;buff[i];++i)
    {
        o*=10,o+=buff[i]-'0';
    }
    o*=f;
}
 
template<typename T>
void write(T o)
{
    int len = 0;
    buff[0] = '0';
    if(o==0)
    {
        putchar('0');
        return;
    }
    int f = 1;
    if(o<0) f = -1;
    o*=f;
    for(;o;o/=10) buff[len++] = o%10+'0';
    if(f==-1) buff[len++] = '-';
    reverse(buff,buff+len);
    buff[len++] ='\0';
    printf("%s",buff);
}
#endif
 
#ifdef FIO
char buff[100];
template<typename T>
void read(T& o)
{
    o = 0;
    scanf("%s",buff);
    //printf("%s\n",buff);
    T f = 1;
    int i = 0;
    if(buff[0]=='-')i++,f = -1;
    for(;buff[i];++i)
    {
        o*=10,o+=buff[i]-'0';
    }
    o*=f;
}
template<typename T>
void write(T o)
{
    int len = 0;
    buff[0] = '0';
    if(o==0)
    {
        putchar('0');
        return;
    }
    int f = 1;
    if(o<0) f = -1;
    o*=f;
    for(;o;o/=10) buff[len++] = o%10+'0';
    if(f==-1) buff[len++] = '-';
    reverse(buff,buff+len);
    buff[len++] ='\0';
    printf("%s",buff);
}
#endif

#define OIreader


#ifdef OIreader
inline int read(){
    char ch; bool sign=0; int res=0;
    while(!isdigit(ch=getchar()))if(ch=='-')sign=1;
    while(isdigit(ch))res=res*10+(ch^48),ch=getchar();
    if(sign)return -res; else return res;
}
#endif

#ifdef _Random_
    mt19937 __MT(chrono::system_clock::now().time_since_epoch().count());
#endif
 
#ifndef BigNumber
    typedef unsigned long long uLL;
    typedef long long LL;
    typedef long long ll;
    typedef pair<LL,LL> pLL;
    typedef vector<LL> vL;
    typedef vector<vL> vLL;
#endif


// Sorry,I must be yellow!

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> pii;


const int maxn = 200000+10;
const LL inf = 1e18;
const int maxm = 10000000+10;
const int base = 2000000+10;
const int apsz = 26;
const LL mod = 998244353;

int n,S;
char s[1<<15];
struct DpRes
{
    map<LL,LL> dp;
    multiset<LL> vals;
    LL addv;
    DpRes(){dp.clear(),vals.clear(),addv = 0;}
    LL operator[](LL o) 
    {
        if(dp.count(o))return addv+dp[o];
        return inf;
    }
    void erase(int y)
    {
        if(!dp.count(y))return;
        //cerr<<y<<" "<<dp[y]<<endl;
        vals.erase(vals.find(dp[y]));
        dp.erase(y);
    }
    void insert(LL x,LL y)
    {
        if(!dp.count(x))
        {
            dp[x] = y;
            vals.insert(y);
        }
        else if(dp[x]>y)
        {
            vals.erase(vals.find(dp[x]));
            vals.insert(y);
            dp[x] = y;
        }
    }
    LL getMin()
    {
        return (*vals.begin())+addv;
    }
    void clear()
    {
        dp.clear();
        vals.clear();
    }
};

DpRes pool[maxn];
int tot;

inline int newDp()
{
    return tot++;
}


struct node
{
    int kind,y,cost;
    node(int a=0,int b=0,int c=0):kind(a),y(b),cost(c){ }
};

node text[maxn];
int endpos[maxn];

inline void merge(DpRes& a,DpRes& b)
{
    for(auto e:b.dp)
    {
        
        a.insert(e.fr,e.sc-a.addv+b.addv);
    }
    //b.clear();
}

int solve(int l,int r,LL st,LL ct)
{
    if(l>r){return -1;}
    int id = newDp();
    pool[id].insert(st,ct);
    for(int i = l;i<=r;)
    {
        if(text[i].kind==0)
        {
            if(text[i].y==S)
            {
                pool[id].addv+=text[i].cost;
            }
            else
            {
                LL minv = pool[id].getMin();
                pool[id].addv+=text[i].cost;
                pool[id].erase(text[i].y);
                pool[id].insert(text[i].y,minv-pool[id].addv);
                
            }
            ++i;
        }
        if(text[i].kind==1)
        {
            if(pool[id].dp.count(text[i].y))
            {
                int t = solve(i+1,endpos[i]-1,text[i].y,pool[id][text[i].y]);
                if(t>=0)
                {
                    pool[id].erase(text[i].y);
                    if(szint(pool[id].dp)<szint(pool[t].dp))
                    {
                        swap(t,id);
                    }
                    merge(pool[id],pool[t]);
                }
            }
            i = endpos[i]+1;
        }
        
    }
    return id;
}


int main(void)
{
    sci(n),sci(S);
    vi sk;
    _rep(i,1,n)
    {
        scanf("%s",s);
        //cerr<<s<<endl;
        int y,v;
        if(s[0]=='s')
        {
            sci(y),sci(v);
            text[i] = node(0,y,v);
        }
        else if(s[0]=='i')
        {
            sci(y);
            text[i] = node(1,y);
            sk.pb(i);
        }
        else 
        {
            text[i] = node(2);
            endpos[sk.back()] = i;sk.pop_back();
        }
    }
    DpRes& ans = pool[solve(1,n,0,0)];
    assert(!ans.vals.empty());
    printf("%lld\n",ans.getMin());
    //cerr<<tmp<<endl;
    return 0;
}

