#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <vector>

using namespace std;

struct chore{
    int endt;
    int t;
    int cnt;
    int pre[110];
}ch[10010];

int main(){
    int n, i, j, mm, t;
    while(cin >> n){
        t = 0;
        for(i = 1; i <= n; i ++){
            scanf("%d %d", &ch[i].endt, &ch[i].cnt);
            for(j = 1; j <= ch[i].cnt; j ++){
                scanf("%d", &ch[i].pre[j]);
            }
        }
        for(i = 1; i <= n; i ++){
            mm = 0;
            for(j = 1; j <= ch[i].cnt; j ++){
                mm = ch[ch[i].pre[j]].endt > mm ? ch[ch[i].pre[j]].endt : mm;
            }
            ch[i].endt += mm;
            t = t > ch[i].endt ? t : ch[i].endt;
        }
        cout << t << endl;
    }
    return 0;
}