#include <stdio.h>
#include <stdlib.h>
int N[] = {0};
int getMass(int p, int m, int n)
{
    if(m)
    {
        N[n] = N[p] + m;
        return N[p] + m;
    }
    else
    {
        N[n] = N[p-1];
        return N[p-1];
    }
}
int main()
{
    int p, m, n, mass = 0;
    scanf("%d", &n);
    for(int i = 1;i <= n;i++)
    {
        scanf("%d%d", &p, &m);
        mass += getMass(p, m, i);
    }
    printf("%d", mass);
    return 0;
}
