program mountain;
Uses Math;
const
    MAXN = 100005;

var
    ANS, N, i, j, maxMountainLength, count : LongInt;
    P, leftLIS, rightLIS, valli, scartato  : Array[0..MAXN-1] of LongInt;
    
begin

    (*assign(input,  'input.txt');  reset(input);
    assign(output, 'output.txt'); rewrite(output);*)

    ReadLn(N);

    for i:=0 to N-1 do
        Read(P[i]);
    ReadLn();
    
     valli[0]:=0; valli[N-1]:=0;
     for i:=1 to N-1 do 
                      if (P[i]<P[i-1]) and (P[i]<P[i+1]) then valli[i]:=1;
                 
    ANS := 0;

	(*leftLIS[i] stores the length of longest increasing subsequence ending at index i*)
	(*rightLIS[i] stores the length of longest decreasing subsequence starting at index i*)

   for i:=0 to  N-1 do begin leftLIS[i]:=1; rightLIS[i]:=1; scartato[i]:=0; end;

	(*Calculate LIS from left to right for each position*)

   for i := 1 to N-1 do
            for j:= 0 to i-1 do
                begin
                  if (P[i] > P[j]) then leftLIS[i] := max(leftLIS[i], leftLIS[j] + 1);
                  if (i>0) and (i<N-1) and (P[i]<P[i-1]) then scartato[i]:=1;          
                end;  
  
	(* Calculate LIS from right to left (decreasing subsequence) for each position*)

   for i := N - 2 downto 0 do
            for  j := i + 1 to N-1 do
                if (P[i] > P[j]) then rightLIS[i] := max(rightLIS[i], rightLIS[j] + 1);
                if (i<N-1) and (i>0) and (P[i]<P[i+1]) then scartato[i]:=1; 
  
	(* Find the maximum length of mountain subsequence*)
	count:=0;
    for i:=0 to N-1 do  if ((scartato[i]=1) and (valli[i]=1)) then count:=count+1;
   maxMountainLength := 0;
   for i := 0 to N-1 do
	(*A valid mountain peak must have at least one element on both sides*)
	(*leftLIS[i] > 1 ensures there's at least one element before peak*)
	(*rightLIS[i] > 1 ensures there's at least one element after peak*)
   if (leftLIS[i] >= 1) and (rightLIS[i] >= 1)  then
  	(*Total mountain length with peak at i Subtract 1 because peak is counted in both leftLIS and rightLIS*)
         maxMountainLength := max(maxMountainLength, leftLIS[i] + rightLIS[i] - 1);
 	(* Minimum removals = total elements - maximum mountain length*)
   ANS:=max (N - maxMountainLength,N - maxMountainLength - count) ; 
   WriteLn(ANS);
end.