Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment.

Amr has *n* different types of chemicals. Each chemical *i* has an initial volume of *a*<sub class="lower-index">*i*</sub> liters. For this experiment, Amr has to mix all the chemicals together, but all the chemicals volumes must be equal first. So his task is to make all the chemicals volumes equal.

To do this, Amr can do two different kind of operations. 
 -  Choose some chemical *i* and double its current volume so the new volume will be 2*a*<sub class="lower-index">*i*</sub> -  Choose some chemical *i* and divide its volume by two (integer division) so the new volume will be <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/527470887c95577094d0c6c100f6bec4842e6d29.png" style="max-width: 100.0%;max-height: 100.0%;"/> 
Suppose that each chemical is contained in a vessel of infinite volume. Now Amr wonders what is the minimum number of operations required to make all the chemicals volumes equal?
The first line contains one number *n* (1 ≤ *n* ≤ 10<sup class="upper-index">5</sup>), the number of chemicals.

The second line contains *n* space separated integers *a*<sub class="lower-index">*i*</sub> (1 ≤ *a*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">5</sup>), representing the initial volume of the *i*-th chemical in liters.
# -*- coding: utf-8 -*-
"""
Created on Mon Oct 19 22:35:07 2015

@author: kevin
"""

nombresolution=int(input())
tableausolution=input()
#tableausolu=tableausolution.split(" ")
#print(tableausolu)
#nombresolution=3
#tableausolution="3 5 6"
tabs=tableausolution.split(" ")

for i in range(nombresolution):
	tabs[i]=int(tabs[i])
tabb=[0]*nombresolution

for i in range(nombresolution):
	tabb[i]=bin(tabs[i])[2:]
minimum=len(tabb[0])
indicemin=0


for i in range(1,nombresolution):
	
	if(len(tabb[i])<minimum):
		minimum=len(tabb[i])
		indicemin=i
#on a trouver le binaire le plus petit pour pas partir trop loin
i=0
flag=0
chainemax=''
while(flag==0 and i<minimum):
	for j in range(nombresolution):
		if(tabb[j][i]!=tabb[indicemin][i]):
			flag=1
	if(flag==0):
		chainemax+=""+tabb[indicemin][i]
	i+=1




def calculelesmax(tabb):
	if(len(tabb)==0):
		return tabb
	maxv=len(tabb[0])
	maxi=[0]
	for i in range(1,len(tabb)):
		if(len(tabb[i])==len(tabb[maxi[0]])):
				maxi+=[i]
		elif(len(tabb[i])>len(tabb[maxi[0]])):
			maxi=[i]
			maxv=len(tabb[i])
	return maxv
	
	

	

def coutmin(tabb,cout,nombresolution,chainemax):
	lchainemax=len(chainemax)
	maxv=calculelesmax(tabb)
	if(maxv==lchainemax):
		return cout
	#1er cas je met tout a Y on calcule le coutY
	coutY=0
#	print(tabb)
	
	for i in range(nombresolution):
	
		coutY+=len(tabb[i])-lchainemax
#	print("coutY")
#	print(coutY)
	#on a le cout de mettre tou le monde a Y
	coutdimension=0
	for i in range(nombresolution):
		if(len(tabb[i])==lchainemax):
			tabb[i]+=''+'0'
			coutdimension+=1
#	print(tabb)
#	print("coutdim")
#	print(coutdimension)
	#TOUT MES CHAINES SONT AU MOINS EGALE LEN(chainemax)+1
	#tout mes chaines sont identique de [0lchainemax]
	i=0
	
	coutderemise=0
	while(i<nombresolution):
		
		if(tabb[i][lchainemax]=='1'):
			taille=len(tabb[i])
			coutderemise+=(len(tabb[i])-lchainemax)+1
			tabb[i]=tabb[i][:lchainemax]
			
			tabb[i]+='0'
		i+=1
#	print(tabb)
	coutY0=coutdimension+coutderemise
#	print("coutY0")
#	print(coutY0)
	chainemaxbis=chainemax+'0'
	coutbis=coutmin(tabb,coutY0,nombresolution,chainemaxbis)
#	print("coutBIS")
#	print(coutbis)
	if(coutY<coutbis):
		return coutY + cout
	return coutbis+cout
	
	
print(coutmin(tabb,0,nombresolution,chainemax))

