import heapq from collections import deque d = deque() n = int(input()) a = [] for i in (input().split()): heapq.heappush(a,((int(i) << 24) + 0)) b = deque(list(map(int, input().split()))) c = n ans = 0xFFFFFFFF mxlist = [0] * n while (c): tmp = list(a) mx = 0 index = 0 for bb in b: t = heapq.heappop(tmp) am = t & 0xFFFFFF bm = t >> 24 bm += bb >> 1 am += 1 mxlist[index] = am if am >= ans: break index += 1 heapq.heappush(tmp, (bm << 24) + am) c -= 1 ans = min(ans, max(mxlist)) b.rotate(1) print(ans)