inp = input()
N = int(inp)

eigyo = []

b = []
Ci = []
for i in range(N):
    N_ = list(map(int, input().split()))
    eigyo.append(N_)
    Ci.append(sum(N_))

P = []
for i in range(N):
    P.append(list(map(int, input().split())))


max_ = 0
rieki = 0

for i in range(len(eigyo)):
    buff = P[i][Ci[i]]
    if i==0:
        max_ = buff
    if buff > max_:
        max_ = buff
    

print(max_)
