#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;

int n,i, j, k, m, u;
struct info1
{
	long long x;
	int y;
};
info1  a[100003];
bool cmp(info1 o1, info1 o2)
{
	return o1.x > o2.x;
}

int abs(int x)
{
	return (x < 0) ? (-x) : (x);
}

long long mx(long long x, long long y)
{
	return (x > y) ? (x) : (y);
}

int main()
{
	cin >> n;
	for (i = 1; i <= n; ++i) {
		cin >> a[i].x;
		a[i].y = i;
	}
	//sort(a + 1, a + n + 1, cmp);
	//for (i = 1; i <= n; ++i) cout << a[i].x << ' ' << a[i].y << "\n";
	long long sol = 0;
	for (i = 1; i < n; ++i)
	for (j = i + 1; j <= n; ++j)
	{
		int nr=floor(log2(abs(a[j].y - a[i].y)));
		sol = max(sol,  a[i].x+ a[j].x-nr);
	}
	cout << sol;


	return 0;
}