#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
#define REP(i,st,ed) for(int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(int i=st,i##end=ed;i>=i##end;--i)
const int maxn=100005;
int n,a[maxn],l[maxn],r[maxn];
int dp[maxn][2];
int main(){
	scanf("%d",&n);
	REP(i,1,n){
		scanf("%d",&a[i]);
		l[i]=log2(a[i]);
		r[i]=l[i]+((1<<l[i])!=a[i]);
	}
	int tot=0;
	REP(i,1,n){
		tot+=r[i];
		dp[i][0]=max(dp[i-1][0]+min(l[i],r[i-1]),dp[i-1][1]+min(l[i],l[i-1]));
		dp[i][1]=max(dp[i-1][0]+min(r[i],r[i-1]),dp[i-1][1]+min(r[i],l[i-1]));
	}
	printf("%d\n",tot-max(dp[n][0],dp[n][1]));
	return 0;
}