#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define mod 1000000007
int n,a[100005];
vector<int>hoge[35];
bool need[100005];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		for(int j=0;j<=30;j++){
			if(a[i] <= (1<<j)){
				if(a[i] != (1<<j)) need[i] = 1; 
				a[i] = j; //cout<<j<<endl;
				break;
			}
		}
	}
	int pre = 0; ll ans = 0;
	for(int i=1;i<=n;i++){
		if(pre < a[i]){
			ans+=a[i]-pre; pre = a[i];
		}
		else if(pre > a[i]){
			pre = a[i]; if(need[i]) pre--;
		}
		else if(need[i]){
			pre--;
		}
	}
	cout<<ans<<endl;
}
	