program hcdx;
var
a,b,c:array[1..10000] of integer;
max,i,j,n:longint;
begin
readln(n);
max:=-maxint;
for i:=1 to n do read(a[i]);
b[1]:=1;
c[n]:=1;
for i:=2 to n do
for j:=0 to i-1 do
if (a[i]>a[j]) and (b[j]+1>b[i]) then b[i]:=b[j]+1;
for i:=n-1 downto 1 do
for j:=n+1 downto i+1 do
if (a[i]>a[j]) and (c[j]+1>c[i]) then c[i]:=c[j]+1;
for i:=1 to n do if max<b[i]+c[i]-1 then max:=b[i]+c[i]-1;
writeln(n-max);
end.
var
a,b,c:array[1..10000] of integer;
max,i,j,n:longint;
begin
readln(n);
max:=-maxint;
for i:=1 to n do read(a[i]);
b[1]:=1;
c[n]:=1;
for i:=2 to n do
for j:=0 to i-1 do
if (a[i]>a[j]) and (b[j]+1>b[i]) then b[i]:=b[j]+1;
for i:=n-1 downto 1 do
for j:=n+1 downto i+1 do
if (a[i]>a[j]) and (c[j]+1>c[i]) then c[i]:=c[j]+1;
for i:=1 to n do if max<b[i]+c[i]-1 then max:=b[i]+c[i]-1;
writeln(n-max);
end.