program sortt;
var
n,x,i,j,ans:longint;
f:text;
a:array[1..10000]of longint;
g:array[1..10000]of boolean;
procedure go;
var k,r:longint;
begin
for k:=1 to a[i]-1 do
if g[k] then ans:=ans+1;
end;
Begin
assign(f,'sortt.in');reset(f);
readln(f,n);
for i:=1 to n do g[i]:=true;
read(f,a[1]);g[a[1]]:=false;
ans:=a[1]-1;
for i:=2 to n-1 do
begin
read(f,a[i]);g[a[i]]:=false;
if (a[i]<>1) then go;
end;
close(f);
assign(f,'sortt.out');rewrite(f);
writeln(f,ans);close(f);
end.