{
TASK:psort
LANG:PASCAL
}

var
   a : array[1..50000] of longint;
   n,br : longint;
procedure Add(x : longint);
var
   l, r : longint;
begin
   if x>a[br] then
      begin
         inc(br);
         a[br]:=x;
      end
   else
      begin
         if x<a[1] then begin a[1]:=x;exit; end;
         l:=1;r:=br;
         while r-l>1 do
            begin
               if a[(l+r) shr 1]>x then
                  r:=(l+r) shr 1
               else
                  l:=(l+r) shr 1;
            end;
         if (x>a[l])and(x<a[r]) then
            a[r]:=x;
      end;

end;
procedure readfile;
var
   f : text;
   ii,x : longint;
begin
   assign(f,'');
   reset(F);
   readln(f,n);
   read(f,a[1]);
   br:=1;
   for ii:=2 to n do
      begin
         read(f,x);
         Add(x);
      end;
   close(F);
end;
begin
   readfile;
   writeln(n-br);
end.
