n=int(raw_input())
c=[]
d=[]
b=[]
i=0
while i<n:
	m=int(raw_input())
	a=map(int,raw_input().split())
	b.append(a)
	c+=a
	i+=1
all=list(set(c))
for i in range(n):
	for j in range(len(all)):
		if all[j] not in b[i]:
			d.append(all[j])
print sum(set(d))-sum(all)