#include<bits/stdc++.h>
#define F(i,a,b) for(register int i=a;i<=b;i=-~i)
using namespace std;const int MAXN=250;
int n,a[MAXN],f[MAXN][MAXN],maxa;
main(){
cin>>n;
F(i,1,n){cin>>a[i];f[i][i]=a[i];}
F(i,1,n)F(j,i,n)F(k,i,j){
if(f[i][k]==f[k+1][j])f[i][j]=max(f[i][j],f[i][k]+1);
maxa=max(maxa,f[i][j]);
}cout<<maxa;
}