#include <bits/stdc++.h>

using namespace std;

int n, x[100005][2], dp[100005][2], ta;

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &ta);
		for (int j = 0; (1 << j) < ta; j++)
			x[i][1]++;
		if (ta == (1 << x[i][1]))
			x[i][0] = x[i][1];
		else
			x[i][0] = x[i][1] - 1;
		// printf("%d %d\n", x[i][0], x[i][1]);
		dp[i][0] = min(dp[i - 1][0] + max(0, x[i][0] - x[i - 1][1]), dp[i - 1][1] + max(0, x[i][0] - x[i - 1][0])) + x[i][1] - x[i][0];
		dp[i][1] = min(dp[i - 1][0] + max(0, x[i][1] - x[i - 1][1]), dp[i - 1][1] + max(0, x[i][1] - x[i - 1][0]));
	}
	printf("%d\n", min(dp[n][0], dp[n][1]));
	return 0;
}