#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long br=0;
    long n;
    long i;
    scanf("%ld",&n);
    long long* a=(long long*)malloc(sizeof(long long)*(n+2));
    for (i=0;i<n;i++)
    {
        scanf("%lld",&a[i]);
    }
    for (i=0;i<n-1;i++)
    {
        while ((a[i]&a[i+1])==0)
        {
            ++a[i+1];
            ++br;
        }
        //cout << (a[i]&a[i+1]) << ' ';
    }
    printf("%lld",br);
    return 0;
}