#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;

#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define endl '\n'
#define pb push_back
#define sz(v) (int)(v).size()
#define all(v) (v).begin(),(v).end()
#define mk make_pair
#define F first
#define S second
#define debug(a) cout << #a << " = " << a << endl;
#define int long long

const int INF = 1000000009;
const ll MOD = 1000000007LL;

int n, s;

struct DP{
	int add;
	map<int, int> dp;
	multiset<int> s;
};

vector<DP> v;

signed main() { 
	cin >> n >> s;
	
	v.pb({});
	v.back().add = 0;
	v.back().dp[0] = 0;
	v.back().s.insert(0);
	
	while ( n -- ) {
		string op;
		cin >> op;
		
		if (op == "set") {
			int y, vv;
			cin >> y >> vv;
			
			if (y == s) {
				v.back().add += vv;
				continue;
			}
			
			int res = *v.back().s.begin();
			if (v.back().dp.find(y) != v.back().dp.end())
				v.back().s.erase(v.back().s.find(v.back().dp[y]));	
			
			v.back().dp[y] = res - vv;
			v.back().add += vv;
			v.back().s.insert(v.back().dp[y]);
			
		}
		else if (op == "if") {
			int y;
			cin >> y;
			if (v.back().dp.find(y) != v.back().dp.end()) {
				int res = v.back().dp[y];
				v.back().s.erase(v.back().s.find(res));
				v.back().dp.erase(y);
				
				v.pb({});
				v.back().add = res + v[sz(v) - 2].add;
				v.back().dp[y] = 0;
				v.back().s.insert(0);
			}
			else {
				v.pb({});
				v.back().add = 1e15;
				v.back().dp[y] = 0;
				v.back().s.insert(0);
			}
		}
		else {
			if (v[sz(v) - 2].dp.size() < v[sz(v) - 1].dp.size()) 
				swap(v[sz(v) - 2], v[sz(v) - 1]);
			
			for (auto i : v.back().dp) {
				if (v[sz(v) - 2].dp.find(i.F) == v[sz(v) - 2].dp.end()) {
					v[sz(v) - 2].dp[i.F] = i.S + v.back().add - v[sz(v) - 2].add;
					v[sz(v) - 2].s.insert(v[sz(v) - 2].dp[i.F]);
					continue;
				}
				if (i.S + v.back().add < v[sz(v) - 2].dp[i.F] + v[sz(v) - 2].add) {
					v[sz(v) - 2].s.erase(v[sz(v) - 2].s.find(v[sz(v) - 2].dp[i.F]));
					v[sz(v) - 2].dp[i.F] = i.S + v.back().add - v[sz(v) - 2].add;
					v[sz(v) - 2].s.insert(v[sz(v) - 2].dp[i.F]);
				}
			}
			
			v.pop_back();
		}
	}
	int ans = LLONG_MAX;
	for (auto i : v.back().dp) ans = min(ans, i.S + v.back().add);
	cout << ans;
}