#include <bits/stdc++.h>
using namespace std;
int n,l[10010],d[10010];
vector<int> a[10010];
struct point{int x;int step;};
queue<point>q;
int ans = 0;
void out(){
for (int i = 1;i<=n;i++){
cout<<i<<"->";
for (int j = 0;j<a[i].size();j++) cout<<a[i][j]<<" ";
cout<<endl;
}
return;
}
int main(){
cin>>n;
for (int i = 1;i<=n;i++){
int p,c;cin>>p;cin>>l[p];
while(cin>>c && c!=0) a[c].push_back(p),d[p]++;
}
for (int i = 1;i<=n;i++) if (d[i]==0) q.push({i,1});
int ml = 0,sp = 1;
while(!q.empty()){
point now= q.front();q.pop();
if (now.step!=sp) ans+=ml,sp=now.step,ml=0;
ml = max(ml,l[now.x]);
for (int i = 0;i<a[now.x].size();i++){
int ee = a[now.x][i];
if (--d[ee] == 0) q.push({ee,now.step+1});
}
}
ans+=ml;
cout<<ans;
return 0;
}