#include<bits/stdc++.h>
#define FOR(i,a,b) for(register int i=(a);i<=(b);i++)
#define REP(i,a,b) for(register int i=(a);i>=(b);i--)
#define pb push_back
#define fi first
#define se second
#define hvie '\n'
#define debug cerr<<("QAQ")<<hvie
const long long inf=0x3f3f3f3f3f3f3f3fll;
using namespace std;
typedef long long ll;
int yh(){
	int ret=0;bool f=0;char c=getchar();
	while(!isdigit(c)){if(c==EOF)return -1;if(c=='-')f=1;c=getchar();}
	while(isdigit(c))ret=(ret<<3)+(ret<<1)+(c^48),c=getchar();
	return f?-ret:ret;
}
const int maxn=2e5+5;
int ls[maxn<<5],rs[maxn<<5];
ll mn[maxn<<5],tag[maxn<<5];
int tot=0;
int n,s;
#define mid ((l+r)>>1)
void ADD(int x,ll v){tag[x]+=v;mn[x]+=v;}
void push_down(int x){
	if(tag[x]){
		if(ls[x])ADD(ls[x],tag[x]);
		if(rs[x])ADD(rs[x],tag[x]);
		tag[x]=0;
	}
}
void push_up(int x){
	mn[x]=inf;
	if(ls[x]) mn[x]=min(mn[x],mn[ls[x]]);
	if(rs[x]) mn[x]=min(mn[x],mn[rs[x]]);
}
void change(int &x,int l,int r,int p,ll val){
	if(!x){x=++tot;mn[x]=inf;tag[x]=0;}
	if(l==r)return mn[x]=val,void();
	push_down(x);
	if(p<=mid) change(ls[x],l,mid,p,val);
	else change(rs[x],mid+1,r,p,val);
	push_up(x);
}
ll ask(int x,int l,int r,int p){
	if(!x) return inf;
	if(l==r)return mn[x];
	push_down(x);
	if(p<=mid) return ask(ls[x],l,mid,p);
	else return ask(rs[x],mid+1,r,p);
}
int merge(int x,int y){
	if(!x||!y) return x|y;
	mn[x]=min(mn[x],mn[y]);
	push_down(x);
	push_down(y);
	ls[x]=merge(ls[x],ls[y]);
	rs[x]=merge(rs[x],rs[y]);
	return x;
}

int solve(int nowval,ll cost){
	char s[10];
	int root=++tot;
	mn[root]=inf;tag[root]=0;ls[root]=rs[root]=0;
	change(root,0,maxn,nowval,cost);
	while(~scanf("%s",s)){
		if(s[0]=='s'){
			int y=yh(),v=yh();
			ll pmin=mn[root];
			// cout<<root<<endl;
			ADD(root,v);
			if(y!=::s)change(root,0,maxn,y,pmin);
		}
		else if(s[0]=='i'){
			int y=yh();ll c=ask(root,0,maxn,y);
			int nex=solve(y,c);
			change(root,0,maxn,y,inf);
			// cout<<ask(root,0,maxn,0)<<' '<<ask(root,0,maxn,1)<<' '<<ask(root,0,maxn,2)<<' '<<endl;
			// cout<<ask(nex ,0,maxn,0)<<' '<<ask(nex,0,maxn,1)<<' '<<ask(nex,0,maxn,2)<<' '<<endl;
			root=merge(root,nex);
		}

		else{
			return root;
		}
	}
	return root;
}
int main(){
	n=yh();s=yh();
	mn[0]=inf;
	int num=solve(0,0);
	cout<<mn[num]<<hvie;

	return 0;
}
/*
5 1
set 1 10
set 2 15
if 2
set 1 7
end
r
*/