import sys
input = sys.stdin.readline
n = int(input())
f = []
for _ in range(n):
  f.append(sum(map(int,input().split())))
ans = 0
noopen = True
akaji = -100000000
for c in f:
  p = list(map(int,input().split()))
  if c == 0:
    ans += p[0]
  else:
    ans += max(p[0:c+1])
    if noopen:
      if p[0] <= max(p[1:c+1]):
        noopen = False
      akaji = max(akaji,max(p[1:c+1])-p[0])
if noopen:
  ans += akaji
print(ans)