import heapq N = int(input()) heap = sorted(list(map(int,input().split()))) hmax = heap[-1] kmax = 0 while 1<1: heap0 = heap[:] M0 = len(heap0) mid = (high+low)//2 cnt = 0 for i in range(mid): if M0==0:break cnt += 1 heap1 = [] M1 = 0 M2 = M0 for _ in range(M2): h = heapq.heappop(heap0) M0 -= 1 if h>>i & 1: h -= 1<0: heapq.heappush(heap1,h) M1 += 1 break if h%(1<0: h -= 1<0: heapq.heappush(heap1,h) M1 += 1 break heapq.heappush(heap1,h) M1 += 1 heap0 += heap1 heapq.heapify(heap0) M0 += M1 if M0==0: high = mid else: low = mid print(high)