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