#pragma GCC optimize(2)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cstdlib>
#define ll long long
#define lim 200000
#define N 200010
#define M 9000000
#define inf 1234567890987654ll
#define add_s(_a,_b) _a=min(inf,_a+_b)
#define up(_o) minn[_o]=min(minn[lef[_o]],minn[rgh[_o]])
using namespace std;
namespace ywy{
	inline int get(){
		int n=0;char c;while((c=getchar())||23333)if(c>='0'&&c<='9')break;
		n=c-'0';while((c=getchar())||23333){
			if(c>='0'&&c<='9')n=n*10+c-'0';else return(n);
		}
	}
	inline int sget(){
		char c;while((c=getchar())||23333)if(c>='a'&&c<='z')break;
		if(c=='s'){
			getchar();getchar();return(1);
		}if(c=='i'){
			getchar();return(2);	
		}getchar();getchar();return(3);
	}ll minn[M],adds[M];int lef[M],rgh[M],dp[N],gn=1,gtree=1;vector<int> vec[N];
	int val[N],cost[N];
	inline void down(int tree){
		ll x=adds[tree];adds[tree]=0;
	//	if(minn[lef[tree]]>=0&&minn[lef[tree]]+x<0){
	//		printf("efgvrgbrg,x=%lld,lef=%lld\n",x,minn[lef[tree]]);	
	//	}if(minn[rgh[tree]]>=0&&minn[rgh[tree]]+x<0){
	//		printf("dtgfgfggbfg,x=%lld,rgh=%lld\n",x,minn[rgh[tree]]);	
	//	}if(adds[lef[tree]]>=0&&adds[lef[tree]]+x<0){
	//		printf("(((((((((,x=%lld,lef=%lld\n",x,adds[lef[tree]]);	
	//	}if(adds[rgh[tree]]>=0&&adds[rgh[tree]]+x<0){
	//		printf(")))))))))))),x=%lld,rgh=%lld\n",x,adds[rgh[tree]]);	
	//	}
		add_s(minn[lef[tree]],x);add_s(adds[lef[tree]],x);
		add_s(minn[rgh[tree]],x);add_s(adds[rgh[tree]],x);
		//minn[lef[tree]]+=x;adds[lef[tree]]+=x;
		//minn[rgh[tree]]+=x;adds[rgh[tree]]+=x;
	}
	void dopt(int l,int r,int &tree,int pt,void (*p)(int)){
		if(!tree)tree=gn,gn++,minn[tree]=inf;
		if(l==r){p(tree);return;}int mid=(l+r)>>1;down(tree);
		if(pt<=mid)dopt(l,mid,lef[tree],pt,p);else dopt(mid+1,r,rgh[tree],pt,p);up(tree);
	}
	int united(int l,int r,int a,int b){
		if(!(a&&b))return(a|b);if(l==r){
			minn[a]=min(minn[a],minn[b]);return(a);
		}down(a);down(b);int mid=(l+r)>>1;lef[a]=united(l,mid,lef[a],lef[b]);
		rgh[a]=united(mid+1,r,rgh[a],rgh[b]);up(a);return(a);
	}int danger,stk[N];ll upd;
	void none(int x){minn[x]=0;}
	void setp(int x){minn[x]=upd;}
	void update(int x){minn[x]=min(minn[x],upd);}
	ll gpt(int l,int r,int tree,int pt){
		if(l==r)return(minn[tree]);down(tree);int mid=(l+r)>>1;
		if(pt<=mid)return(gpt(l,mid,lef[tree],pt));return(gpt(mid+1,r,rgh[tree],pt));	
	}
	void dfs(int pt){
		dopt(0,lim,dp[pt],val[pt],none);
	//	if(minn[dp[pt]]<0)printf("12345678909876543211234567890\n");
		for(register int i=0;i<vec[pt].size();i++){
			int me=vec[pt][i];if(cost[me]==-1){
				ll x=gpt(0,lim,dp[pt],val[me]);
			//	printf("x=%lld\n",x);
				if(x<inf){
	//				if(x<=-inf){
	//					printf("x=%lld\n",x);
	//					printf("__________________\n");	
	//				}
					dfs(me);minn[dp[me]]+=x;adds[dp[me]]+=x;
					upd=inf;dopt(0,lim,dp[pt],val[me],setp);
					dp[pt]=united(0,lim,dp[pt],dp[me]);	
				}
			}else{
				ll m=minn[dp[pt]];adds[dp[pt]]+=cost[me];minn[dp[pt]]+=cost[me];
			//	printf("set %d %d!!!!  m=%lld,minn=%lld\n",val[me],cost[me],m,minn[dp[pt]]);
			//	printf("get2=%lld\n",gpt(0,lim,dp[pt],2));
				if(val[me]!=danger){
					upd=m;dopt(0,lim,dp[pt],val[me],update);	
				}
			}
		}//if(minn[dp[pt]]<0){
		//	printf("uhrvgubruburtfvbgr %lld\n",minn[dp[pt]]);	
		//}
	}
	void ywymain(){
		//freopen("test.in","r",stdin);
		minn[0]=inf;int n=get(),sp=1;danger=get();
		for(register int i=1;i<=n;i++){
			int op=sget();if(op==1){
				int me=gtree;gtree++;val[me]=get();cost[me]=get();
				vec[stk[sp-1]].push_back(me);
			}if(op==2){
				int me=gtree;gtree++;val[me]=get();cost[me]=-1;
				vec[stk[sp-1]].push_back(me);stk[sp]=me;sp++;
			}if(op==3)sp--;
		}dfs(0);cout<<minn[dp[0]]<<endl;
	}
}
signed main(){
	ywy::ywymain();return(0);	
}