n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) inf = 10**6 x = [[] for _ in range(inf + 1)] for i in range(n): x[a[i]].append(a[i] + b[i]) ok = [0] * (inf + 1) ok[1] = 1 ans = 0 for i in range(inf + 1): if not ok[i]: continue ans = i for j in x[i]: ok[j] = 1 print(ans)