#include <iostream>

using namespace std;

long long max, current;

long long v[100001];
int n;

long long log_base_2(long long value)
{
    long long result = -1;
    while (value != 0)
    {
        value = value >> 1;
        result++;
    }
    return result;
}

int main()
{

    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            current = v[j] + v[i] - log_base_2(j - i);
            if (current > max)
            {
                max = current;
            }
        }
    }
    cout << max;
}