{
TASK:psort
LANG:PASCAL
}

var
  a: array[1..50000] of Longint;
  pos: array[1..50000] of Longint;  
  n,i,j: Integer;
  st,br: Longint;


begin
  readln(n);
  for i:= 1 to n do
    read(a[i]);
  for i:= 1 to n do
    for j:= 1 to n do
      if a[j]=i then
        pos[i]:= j;
  br:= 0;
  for i:= 2 to n do
  begin
    if (pos[i-1]+1<>pos[i]) and (pos[i]<>i) then
    begin
      br:= br+1;
      pos[i]:= pos[i-1]+1;
      st:= pos[i];
      if i+1<=n then
        for j:= i+1 to n do
          if pos[j]>=st then
          begin
            pos[j]:= st+1;
            st:= st+1;
          end;
    end;
  end;
  writeln(br);
end.