f = open('fff.txt')
a = {}
for s in f:
x = s.split()
if len(x) >= 3 and x[0].isdigit():
a[int(x[0])] = (int(x[1]), x[2])
end = {}
def finish(i):
if i not in end:
t, deps = a[i]
if deps == '0':
start = 1
else:
start = max(finish(int(j)) for j in deps.split(';')) + 1
end[i] = start + t - 1
return end[i]
count = 0
for i in a:
finish(i)
t, deps = a[i]
start = end[i] - t + 1
if start <= 7 <= end[i]:
count += 1
print(count)