#include <cstring>
#include <algorithm>
#include <cstdio>

using namespace std;
const int MAXN = 100010;
int _w;

int n, a[MAXN], l[MAXN], r[MAXN], x[MAXN];

int lowb( int x ) {
	for( int i = 0; i <= 30; ++i )
		if( x & (1<<i) ) return i;
	return -1;
}
int highb( int x ) {
	for( int i = 30; i >= 0; --i )
		if( x & (1<<i) ) return i;
	return -1;
}

int fl[MAXN], fr[MAXN];
int solve() {
	for( int i = 1; i < n; ++i ) {
		fl[i] = max( fl[i-1] + min(r[i-1], l[i]), fr[i-1] + min(l[i-1], l[i]) );
		fr[i] = max( fl[i-1] + min(r[i-1], r[i]), fr[i-1] + min(l[i-1], r[i]) );
	}
	return max(fl[n-1], fr[n-1]);
}

int main() {
	_w = scanf( "%d", &n );
	int ans = 0;
	for( int i = 0; i < n; ++i ) {
		_w = scanf( "%d", a+i );
		if( lowb(a[i]) == highb(a[i]) )
			l[i] = r[i] = x[i] = highb(a[i]);
		else
			l[i] = x[i] = highb(a[i])+1, r[i] = l[i]-1;
		ans += x[i];
	}
	printf( "%d\n", ans - solve() );
	return 0;
}
