#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,a[100100];
int ans;
int c[100100][61];
int f[100100][61];
signed main(){
cin>>n;
for (int i=1;i<=n;i++)
cin>>a[i];
ans=n;
memset(f,-63,sizeof(f));
f[0][0]=1;
for (int i=1;i<n;i++){
int x=a[i+1]-a[i];
int len=63^__builtin_clzll(x);
for (int j=0;j<len;j++)c[i][j]=1ll<<j;
c[i][len]=x-(1ll<<len);
for (int j=0;j<len;j++)
for (int k=0;k<=j;k++)
f[i][j]=max(f[i][j],f[i-1][k]+c[i][j]);
f[i][len]=max(f[i][len],f[i-1][len]+c[i][j]);
if(c[i][len]!=0){
int tmp=max(1ll<<len-1,c[i][len])+1;
for (int k=0;k<len;k++)
f[i][len]=max(f[i][len],f[i-1][k]+tmp);
}
for (int j=0;j<=60;j++)
f[i][j]=max(f[i][j],f[i-1][j]);
}
for (int j=0;j<=60;j++)
ans=max(ans,f[n-1][j]);
cout<<ans<<"\n";
}