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

using namespace std;

#pragma GCC diagnostic ignored "-Wsign-compare"
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);
			}
		}
};
#pragma GCC diagnostic pop

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();
		}
};

template <typename Value> class Good_Multiset : public multiset<Value> {
	public:
		using multiset<Value>::multiset;
		void erase_one (const Value &value) {
			this -> erase ( this -> find(value) );
		}
		void erase_all (const Value &value) {
			this -> erase(value); // IMPORTANT MISTAKE: multiset's erase (value&) actually erases ALL OCCURENCES of value, not just a single one
		}
};

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;
	int skip = false;
	Safe_Stack<int> condition( {0} );
	Safe_Stack<long long> cost( {0} );
	Safe_Stack< Good_Map<int, long long> > discount( { { {0, 0} } } );
	Safe_Stack< Good_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_one (
				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;
			
			if (not skip) {
				cost[indent] += v;
				if (y != s)
					update_discount(y, indent, min_price(indent) - v);
			}
		}

		else if (command == "if") {
			int y;
			cin >> y;
			++indent;
			if (not skip and not discount[indent - 1].contains(y))
				skip = indent;

			if (not skip) {
				condition.push(y);
				cost.push( price(y, indent - 1) );
				discount.push( { {y, 0} } );
				discounts.push( {0} );
			}
		}

		else if (command == "end") {
			if (not skip) {
				if (discount[indent - 1].size() <= discount[indent].size()) {
					for (const auto &[value, unused_variable] : discount[indent - 1])
						if (
							(
								not discount[indent].contains(value)
								or price(value, indent) > price(value, indent - 1)
							)
							and value != condition[indent]
						)
							update_discount(value, indent, price(value, indent - 1));
					swap(cost[indent - 1], cost[indent]);
					swap(discount[indent - 1], discount[indent]);
					swap(discounts[indent - 1], discounts[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));
				}
				condition.pop(), cost.pop(), discount.pop(), discounts.pop();
			}
			if (skip == indent)
				skip = false;
			--indent;
		}
	}

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