#include<cstring>
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
int n,i,j,k;
int f[300];
int a[300];
int lnv[300];
int main()
{
freopen("ladder.in","r",stdin);
freopen("ladder.out","w",stdout);
scanf("%d",&n);
lnv[0]=1;
memset(f,1,sizeof(f));
for (i=1;i<=n;i++)
lnv[i]=lnv[i-1]<<1;
for (i=1;i<=n;i++)
scanf("%d",&a[i]);
f[1]=0;
for (i=2;i<=n;i++){
if (a[i]-a[i-1]==1)
f[i]=f[i-1]+1;
for (j=n-1;j>=1;j--)
for (k=j+1;k<=n-1;k++)
if (a[j]+lnv[k-j]>=a[i])
if (f[k]+k-j+1<f[i])
f[i]=f[k]+k-j+1;
}
printf("%d",f[n]);
return 0;
}