N = int(input()) A = list(map(int,input().split())) B = list(map(int,input().split())) C = [(A[i],B[i]) for i in range(N)] C.sort() s = set() s.add(1) for a,b in C: if a in s: s.add(a + b) print(max(s))