from bisect import bisect_left n = int(input()) a = sorted(map(lambda i: int(i) * 2000, input().split())) + [10 ** 9] b = list(map(lambda i: int(i) // 2, input().split())) def f(i): pq = a[:] for e in b[i:] + b[:i]: l = pq.pop(0) up = l + e * 2000 + 1 pq.insert(bisect_left(pq, up), up) return max(x % 2000 for x in pq[:-1]) print(min(f(i) for i in range(n)))