n = int(input())
F = [sum(map(int, input().split())) for _ in range(n)]
P = [list(map(int, input().split()))[:(F[n_i]+1)] for n_i in range(n)]

ans = 0
all_entry_zero = True

for p_i in P:
  
  ans += max(p_i)
  if max(p_i) in p_i[1:]:
    all_entry_zero = False

if all_entry_zero:
  ans = max(list(max(p_i[1:]) for p_i in P))
  
print(ans)