
// Problem: G. Forbidden Value
// Contest: Codeforces - Educational Codeforces Round 99 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1455/problem/G
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
 
inline int read()
{
    int s = 0, w = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            w = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
        s = s * 10 + ch - '0', ch = getchar();
    return s * w;
}
 
const int MAXN = 2e5 + 10;
const int INF = 1e18;
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const double PI = acos(-1.0);
 
int n, s;
 
struct Node
{
	int offset;
	map<int, int> mp;
	multiset<int> ms;
};
 
vector<Node> vec;
 
void update(Node &node, int y, int v)
{
	if (node.mp.count(y))
	{
		node.ms.erase(node.ms.find(node.mp[y]));
	}
	node.mp[y] = v;
	node.ms.insert(v);
}
 
signed main()
{
    n = read(), s = read();
    int skip = 0;
    vec.push_back({});
    vec.back().offset = 0;
    vec.back().mp[0] = 0;
    vec.back().ms.insert(0);
    for (int i = 0; i < n; i++)
    {
    	string op;
    	int y, v;
    	cin >> op;
    	if (op[0] == 's')
    	{
    		y = read(), v = read();
    		if (skip) continue;
    		int minV = *vec.back().ms.begin() - v;
    		vec.back().offset += v;
    		if (y != s)
    		{
    			update(vec.back(), y, minV);
    		}
    	}
    	else if (op[0] == 'i')
    	{
    		y = read();
    		if (!skip && vec.back().mp.count(y))
    		{
    			int val = vec.back().mp[y] + vec.back().offset;
    			vec.back().ms.erase(vec.back().ms.find(vec.back().mp[y]));
    			vec.back().mp.erase(y);
    			vec.push_back({});
    			vec.back().offset = 0;
    			update(vec.back(), y, val);
    		}
    		else
    		{
    			skip++;
    		}
    	}
    	else
    	{
    		if (skip) skip--;
    		else
    		{
    			if (vec[vec.size() - 1].mp.size() > vec[vec.size() - 2].mp.size())
    			{
    				swap(vec[vec.size() - 1], vec[vec.size() - 2]);
    			}
    			auto &outer = vec[vec.size() - 2];
    			for (auto x : vec.back().mp)
    			{
    				if (!outer.mp.count(x.first) || (outer.offset + outer.mp[x.first] > vec.back().offset + x.second))
    				{
    					int val = vec.back().offset + x.second - outer.offset;
    					update(outer, x.first, val);
    				}
    			}
    			vec.pop_back();
    		}
    	}
    }
    cout << vec.back().offset + *vec.back().ms.begin() << endl;
    return 0;
}