#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 100005;

int n, ret, a[MAXN];

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = Read();
	for (int i = 1; i <= n; i ++)
		a[i] = Read();
	for (int i = 29; ~i; i --)
	{
		bool flg = false;
		for (int j = 1; j <= n; j ++)
			if (a[j] > 1 << i)
			{
				if (a[j] == 1 << i + 1)
					flg = true;
				else if (!flg)
					flg = true;
				else
					flg = false, ret ++;
				a[j] = 1 << i;
			}
			else
				ret += flg, flg = 0;
		ret += flg;
	}
	return printf("%d\n", ret), 0;
}
