#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

template <typename Value> class Safe_Vector : public vector<Value> {
	public:
		using vector<Value>::vector;
		Value &operator [] (const int &index) {
			if (0 <= index and index < this -> size())
				return *(this -> data() + index);
			else {
				cout << "attempt to access index " << index << " from a 0-based vector of size " << this -> size() << endl;
				exit(1);
			}
		}
		Value &front () {
			if (not this -> empty())
				return *(this -> data());
			else {
				cout << "attempt to access front element from an empty vector" << endl;
				exit(1);
			}
		}
		Value &back () {
			if (not this -> empty())
				return *(this -> data() + this -> size() - 1);
			else {
				cout << "attempt to access back element from an empty vector" << endl;
				exit(1);
			}
		}
};

template <typename Value> class Safe_Stack : public Safe_Vector<Value> {
	public:
		using Safe_Vector<Value>::Safe_Vector;
		void push (const Value &value) {
			this -> push_back(value);
		}
		void pop () {
			this -> pop_back();
		}
};

template <typename Key, typename Value> class Good_Map : public map<Key, Value> {
	public:
		using map<Key, Value>::map;
		bool contains (const Key &key) {
			return this -> find(key) != this -> end();
		}
};

const int MAX_N = 2e5, MAX_V = 1e9;

void optimize_IO () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
}

int main () {
	optimize_IO();
	int n, s;
	cin >> n >> s;

	int indent = 0;
	Safe_Stack<int> condition( {0} );
	Safe_Stack<long long> cost( {0} );
	Safe_Stack< Good_Map<int, long long> > discount( { { {0, 0} } } );
	Safe_Stack< multiset<long long> > discounts( { {0} } );

	auto price = [&cost, &discount] (const int &value, const int &indent) {
		return cost[indent] - discount[indent][value];
	};
	auto update_discount = [&cost, &discount, &discounts] (const int &value, const int &indent, const long long &price) {
		if (discount[indent].contains(value))
			discounts[indent].erase(
				discounts[indent].find( discount[indent][value] )	
			);
		discounts[indent].insert(
			discount[indent][value] = cost[indent] - price
		);
	};
	auto min_price = [&cost, &discounts] (const int &indent) {
		return cost[indent] - *discounts[indent].rbegin();
	};

	for (; n > 0; --n) {
		string command;
		cin >> command;

		if (command == "set") {
			int y, v;
			cin >> y >> v;
			cost[indent] += v;
			if (y != s)
				update_discount(y, indent, min_price(indent) - v);
		}

		else if (command == "if") {
			int y;
			cin >> y;
			++indent;
			condition.push(y), cost.push( (discount[indent - 1].contains(y) ? price(y, indent - 1) : 0) ), discount.push( { {y, 0} } ), discounts.push( {0} );
		}

		else if (command == "end") {
			if ( discount[indent - 1].contains(condition[indent]) ) {
				if (discount[indent - 1].size() <= discount[indent].size()) {
					swap(cost[indent - 1], cost[indent]);
					swap(discount[indent - 1], discount[indent]);
					swap(discounts[indent - 1], discounts[indent]);
					for (const auto &[value, unused_variable] : discount[indent])
						if (
							not discount[indent - 1].contains(value)
							or price(value, indent - 1) > price(value, indent)
							and value != condition[indent]
						)
							update_discount(value, indent - 1, price(value, indent));
				} else {
					for (const auto &[value, unused_variable] : discount[indent])
						if (
							not discount[indent - 1].contains(value)
							or price(value, indent - 1) > price(value, indent)
							or value == condition[indent]
						) {
							update_discount(value, indent - 1, price(value, indent));
							/*if (n == 199813) {
								cout << "last updated value: " << value << endl;
								// cout << "condition indent: " << condition[indent] << endl;
								// cout << "indent - 1: " << indent - 1 << endl;
								cout << "cost[indent - 1]: " << cost[indent - 1] << endl;
								cout << "discount[indent - 1]: " << endl;
								for (const auto &[value, discount] : discount[indent - 1])
									cout << "value: " << value << ", discount: " << discount << endl;
								cout << "discounts: " << endl;
								for (const int &discount : discounts[indent - 1])
									cout << discount << endl;
								// cout << "indent: " << indent << endl;
								cout << "cost[indent]: " << cost[indent] << endl;
								cout << "discount[indent]: " << endl;
								for (const auto &[value, discount] : discount[indent])
									cout << "value: " << value << ", discount: " << discount << endl;
								cout << "discounts: " << endl;
								for (const int &discount : discounts[indent])
									cout << discount << endl;
							}*/
						}
				}
			}
			condition.pop(), cost.pop(), discount.pop(), discounts.pop();
			--indent;
		}

		/*cout << "indent: " << indent << endl;
		for (const auto &[value, discount] : discount[indent])
			cout << "price of " << value << ": " << price(value, indent) << endl;
		cout << "min price: " << min_price(indent) << endl;*/

		/*if (n == 199813)
			exit(1);*/
	}

	cout << min_price(0) << '\n';
}


