program Project1;
type arr=array [1..2200] of longint;
var a,f,b:arr;
z,n,i:longint;
procedure lis(n:longint);
var
i,j:longint;
begin
for i:=1 to n do b[i]:=1;
for i:=n-1 downto 1 do
for j:=n downto i+1 do
if (a[j]>a[i]) and (b[j]+1>b[i]) then
b[i]:=b[j]+1;
end;
procedure lis2(n:longint);
var
i,j:longint;
begin
for i:=1 to n do f[i]:=1;
for i:=n-1 downto 1 do
for j:=n downto i+1 do
if (a[j]<a[i]) and (f[j]+1>f[i]) then
f[i]:=f[j]+1;
end;
begin
while not eof do
begin
readln(n);
for i:=1 to n do readln(a[i]);
lis(n);
lis2(n);
for i:=1 to n do f[i]:=f[i]+b[i]-1;
z:=f[1];
for i:=2 to n do
if z<f[i] then z:=f[i];
writeln(z);
end;
end.