import heapq from collections import deque n=input() a=map(int,raw_input().split())+[1e9] b=deque(map(int,raw_input().split())) max_list=[] for _ in range(n): pq=[(j,0) for j in a] heapq.heapify(pq) for elevel in b: level,cnt=heapq.heappop(pq) heapq.heappush(pq,(level+elevel/2,cnt+1)) max_list.append(max([y for x,y in pq])) b.rotate() print min(max_list)