#include <iostream>
#include <cstdio>
#include <vector>
#include <fstream>
using namespace std;
int main(void)
{
ifstream fin("262144.in");
ofstream fout("262144.out");
int n, res = 0;
fin >> n;
vector<int> A(n);
vector<vector<int>> range(2, vector<int>(n+2, -1));
for(int i = 0;i < n;i++)
{
fin >> A[i];
res = max(res, A[i]);
}
for(int k = 1;k <= 65;k++)
{
for(int i = 0;i < n;i++)
{
if(A[i] == k-1) range[0][i] = i;
}
for(int i = 0;i < n;i++)
{
if(range[0][i] != -1)
{
if(range[0][range[0][i]+1] != -1)
{
res = max(res, k);
range[1][i] = range[0][range[0][i]+1];
}
}
}
range[0] = range[1];
range[1].clear(); range[1].resize(n+2, -1);
}
fout << res << "\n";
}
CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGZzdHJlYW0+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbih2b2lkKQp7CglpZnN0cmVhbSBmaW4oIjI2MjE0NC5pbiIpOwoJb2ZzdHJlYW0gZm91dCgiMjYyMTQ0Lm91dCIpOwoJaW50IG4sIHJlcyA9IDA7CglmaW4gPj4gbjsKCXZlY3RvcjxpbnQ+IEEobik7Cgl2ZWN0b3I8dmVjdG9yPGludD4+IHJhbmdlKDIsIHZlY3RvcjxpbnQ+KG4rMiwgLTEpKTsKCWZvcihpbnQgaSA9IDA7aSA8IG47aSsrKQoJewoJCWZpbiA+PiBBW2ldOwoJCXJlcyA9IG1heChyZXMsIEFbaV0pOwoJfQoKCWZvcihpbnQgayA9IDE7ayA8PSA2NTtrKyspCgl7CgkJZm9yKGludCBpID0gMDtpIDwgbjtpKyspCgkJewoJCQlpZihBW2ldID09IGstMSkgcmFuZ2VbMF1baV0gPSBpOwoJCX0KCQlmb3IoaW50IGkgPSAwO2kgPCBuO2krKykKCQl7CgkJCWlmKHJhbmdlWzBdW2ldICE9IC0xKQoJCQl7CgkJC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