#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include<functional>
#define mod 1000000007
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
using namespace std;
typedef long long ll;
const int N=10005;
const int M=150005;
int vis[N];
int id[N];
vector<int>q[N];
int n,m,x,y,h;
int ans,maxn=0,sum=0;
int dp[N];
int main() {
scanf("%d",&n);
h=n;
while(h--){
scanf("%d%d",&x,&y);
id[x]=y;
while(~scanf("%d",&m)&&m){
q[x].push_back(m);
vis[m]=1;
}
if(q[x].size()==0)q[0].push_back(x);
}
for(int i=0;i<q[0].size();i++){
dp[q[0][i]]=id[q[0][i]];
}
for(int i=1;i<=n;i++){
for(int j=0;j<q[i].size();j++){
dp[i]=max( dp[q[i][j]]+id[i],dp[i]);
}
//printf("%d %d\n",i,dp[i]);
}
for(int i=1;i<=n;i++){
if(!vis[i])maxn=max(maxn,dp[i]);
}
printf("%d\n",maxn);
return 0;
}