#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include <complex>

using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;
const int MOD = 998244353;

const double EPS = 1e-6;
const int MAX = 300 * 1000 + 47;


int main()
{
    int n;
    scanf("%d", &n);
    int ans = 0, lst = 0;
    FOR(i, 0, n)
    {
        int x;
        scanf("%d", &x);
        int lg = 0;
        while((1 << lg) < x)++lg;
        ans += lg;
        ans -= min(lst, lg);
        lst = lg - 1 + ((1 << lg) == x || lg-1 >= lst);
    }
    
    cout << ans << endl;
    
    return 0;
}
