

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_))

#list = range(0, 5, 2)
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 buff > max_:
        max_ = buff

print(max_)
