#include <iostream>
#include <stack>
#include <vector>

#define endl '\n'

using namespace std;

const int MAXN = 1e6 + 3;
int weights[MAXN];
vector<int> snowballs[MAXN];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;

    for (int i = 1; i <= n; ++i) {
        int p, m;
        cin >> p >> m;

        snowballs[i] = snowballs[p];
        weights[i] = weights[p];

        /*if (m == 0) {
            weights[i] -= snowballs[i].top();
            snowballs[i].pop();
        } else {
            weights[i] += m;
            snowballs[i].push(m);
        }*/
    }

    int total_weight = 0;
    for (int i = 0; i <= n; ++i) {
        total_weight += weights[i];
    }

    cout << total_weight << endl;

return 0;
}
