#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl '\n'
#define all(v) (v).begin(), (v).end()
template<class A, class B> ostream& operator<<(ostream& os, const pair<A,B>& p) {
	return os << '(' << p.first << ", " << p.second << ')';
}
template<class T> auto operator<<(ostream& os, T&& x) -> decltype(x.begin(), os) {
	os << '{';
	for(auto it = x.begin(); it != x.end(); ++it) os << *it << (it == prev(x.end()) ? "" : ", ");
	return os << '}';
}
void dump() {}
template<class T,class... Args> void dump(T&& x,Args... args) { cerr<<x<<";  "; dump(args...); }
#ifdef DEBUG
    struct Lf{ ~Lf() { cerr << '\n'; } };
    #define debug(x...) cerr << (strcmp(#x, "") ? #x ":  " : ""), dump(x), Lf(), cerr << ""
#else
    #define debug(...) 0&&cerr
#endif

int n,s;
int cnt = 0;
string cmd;
int y, v;

struct blockDP {
    unordered_map<int,ll> DP;
    set<pair<ll, int>> costs;
    ll offset = 0;

    void inc(ll cost) {
        offset += cost;
    }
    void ins(int xval, ll cost) {
        if (DP.count(xval)) {
            cost = min(cost, rem(xval));
        }
        cost -= offset;
        DP[xval] = cost;
        costs.insert({cost, xval});
    }
    ll rem(int xval) {
        if (DP.count(xval) == 0) return 1e16;

        ll DPcost = DP[xval];
        DP.erase(xval);
        costs.erase({DPcost, xval});
        return DPcost + offset;
    }
    ll get_cost(int xval) {
        if (DP.count(xval) == 0) return 1e16;

        return DP[xval] + offset;
    }
    ll get_min_cost() {
        return costs.begin()->first + offset;
    }
    int size() {
        return DP.size();
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin >> n >> s;
    vector<blockDP> blockstack(1);
    blockstack[0].ins(0,0);

    for (int i=0; i<n; ++i) {
        cin >> cmd;
        if (cmd == "if") {
            cin >> y;
            ll entry_cost = blockstack.back().rem(y);
            blockstack.emplace_back();
            blockstack.back().ins(y, entry_cost);
        }
        else if (cmd == "end") {
            blockDP& inner = blockstack.back();
            blockDP& outer = blockstack[blockstack.size() - 2];

            if (inner.size() > outer.size()) swap(inner, outer);
            for (auto& xx : inner.DP) outer.ins(xx.first, inner.get_cost(xx.first));

            blockstack.pop_back();
        }
        else if (cmd == "set") {
            cin >> y >> v;
            if (y == s) {
                blockstack.back().inc(v);
            }
            else {
                ll base_cost = blockstack.back().get_min_cost();
                blockstack.back().inc(v);
                blockstack.back().ins(y, base_cost);
            }
        }
    }

    ll ans = blockstack[0].get_min_cost();
    cout << ans << endl;

    return 0;
}