Var a,b,N:int64;
i,y:longint;
X:array [1..200001] of int64;
Begin
 readln(N);
 for i:=1 to N do
  read(X[i]);
 While a<>-1 do begin
 a:=X[1];
 for i:=1 to N do
  if X[i]>a then a:=X[i];
  if a=1 then a:=-1;
 for i:=1 to N do
  if X[i]=a then
          for y:=i to N do begin
           if X[y]=a then X[y]:=X[y]-1;
           if X[y+1]<>a then a:=0; end;
  b:=b+1;
  end;
 Writeln(b);
 End.

