N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
sum_p = []
cnt = 0
minn = []
for i in range(N):
    cnt_open = F[i].count(1)
    max_p = max(P[i][0:cnt_open+1])
    min_p = min(P[i][1:cnt_open+1])
    sum_p.append(max_p)
    minn.append(min_p)
    
    if max_p == P[i][0]:
        cnt += 1
if cnt == N:
    print(min(minn))
else:
    print(sum(sum_p))
