Program ubhuiwrhg;
var n, i, g, k, x : integer;
m : array [1..20000] of longint;
f: boolean;
begin
f:=false;
k:=0;
readln(n);
for i:= 1 to n do
read(m[i]);
x:=1;
for i:= 1 to n do
if m[i] > x then x:=m[i];
for i:=1 to x do
begin
for g:=1 to n do
begin
if (m[g]=x-i+1) then
begin
m[g]:=m[g]-1;
if f=false then
begin
k:=k+1;
f:=true;
end;
end
else f:=false;
end;
f:=false;
end;
write(k);
end.
