1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
n = int(input())


class platforma:
    platformy = []
    stany = []
    def __init__(self, num, tasmociagi):
        self.num = num
        self.tasmociagi = tasmociagi
        self.kierunki = len(tasmociagi)
        self.kierunek = 0
        platforma.platformy.append(self)
        platforma.stany.append(0)

    def walizka(self):
        if self.kierunki:
            platforma.platformy[self.tasmociagi[self.kierunek]-1].walizka()
            self.kierunek += 1
            if self.kierunek == self.kierunki: self.kierunek = 0
            platforma.stany[self.num] = self.kierunek


for i in range(n):
    w = tuple(map(int, input().split()))
    platforma(i, w[1:])

walizki = 0

while True:
    walizki += 1
    platforma.platformy[0].walizka()
    if not any(platforma.stany): break

print(walizki)