/*
This is code of SuperJ6 for Codeforces.
Don't copy my code during f*kin' contests.

2.71828182845904523536
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<ll, ll>
#define f first
#define s second

struct T{
	map<ll, ll> dp;
	multiset<ll> mn;
	ll v, lz;
};

ll n, k;
stack<T*> stk;

T* tp(){
	return stk.top();
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	
	stk.push(new T());
	tp()->mn.insert(tp()->dp[0] = 0);
	while(n--){
		string s;
		cin >> s;
		if(s == "if"){
			stk.push(new T());
			cin >> tp()->v;
			tp()->mn.insert(tp()->dp[tp()->v] = 0);
		}else if(s == "end"){
			T *p = tp();
			stk.pop();
			if(tp()->dp.count(p->v)){
				ll x = tp()->dp[p->v];
				p->lz += x + tp()->lz;
				tp()->dp.erase(p->v);
				tp()->mn.erase(tp()->mn.find(x));
				
				if(tp()->dp.size() < p->dp.size()) swap(stk.top(), p), swap(tp()->v, p->v);
				for(pi i : p->dp){
					x = i.s + p->lz - tp()->lz;
					if(!tp()->dp.insert({i.f, x}).s){
						ll y = tp()->dp[i.f];
						if(x < y){
							tp()->mn.insert(tp()->dp[i.f] = x);
							tp()->mn.erase(tp()->mn.find(y));
						}
					}else{
						tp()->mn.insert(x);
					}
				}
			}
		}else{
			ll x, y;
			cin >> x >> y;
			tp()->lz += y;
			if(x != k){
				y = *tp()->mn.begin() - y;
				if(tp()->dp.count(x)){
					tp()->mn.erase(tp()->mn.find(tp()->dp[x]));
					tp()->dp.erase(x);
				}
				tp()->mn.insert(tp()->dp[x] = y);
			}
		}
	}
	
	cout << (*tp()->mn.begin() + tp()->lz) << endl;

	return 0;
}