#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>

#define ll long long

int main(){
	ll N;
	scanf("%lld", &N);
	std::vector<ll> input(N, 0);
	for(ll i = 0; i < N; i++){
		ll p, m;
		scanf("%lld %lld", &p, &m);
		if(m > 0) input[i] = input[p] + m;
		else if(m == 0) input[i] = input[p] - 1;
	}
	printf("%lld", input[input.size() - 1]);
	return 0;
}
