n = int(input())
f = [list(map(int,input().split())) for _ in range(n)]
p = [list(map(int,input().split())) for _ in range(n)]

p0 = []
maxp = []
for i in range(n):
    p0.append(p[i][0])
    sumf = sum(f[i])
    maxp.append(max(p[i][1:(sumf+1)]))

cnt = 0
sum_max = []
for i in range(n):
    if p0[i] > maxp[i]:
        cnt += 1
    sum_max.append(max(p0[i],maxp[i]))
    
if cnt == n:
    a = []
    for i in range(n):
        a.append(p0[i] - maxp[i])
    print(sum(p0) - min(a))
else:
    print(sum(sum_max))