from heapq import heappushpop N = int(input()) WEAKEST, *A = sorted(map(lambda x: int(x)*10000, input().split())) B = list(map(lambda x: int(x)//2*10000+1, input().split())) ans = 10**9 for i in range(N): a = A[:] weakest = WEAKEST for exp in B[i:] + B[:i]: weakest = heappushpop(a, weakest+exp) ans = min(ans, max(n % 10000 for n in a+[weakest])) print(ans)