program Zeroing;
var N,m,i,l:word;
    a:array [1..100000] of word;
begin
 readln (N);
 readln(a[i]);
 l:=0;
 begin
  a[i]:=a[1];
  for i:=1 to N do
   begin
   if a[i+1]>a[i]
    then
     a[i]:=a[i+1];
   end;
  if a[i-1]=a[i]
   then
    a[i]:=a[i]-1;
    a[i-1]:=a[i-1]-1;
  if a[i+1]=a[i]
   then
    a[i]:=a[i]-1;
    a[i+1]:=a[i+1]-1;
  if a[i]<>a[i+1]
    then
   a[i]:=a[i]-1;
  if a[i]<>a[i-1]
   then
   a[i]:=a[i]-1;
 l:=l+1;
 while a[i]<>1 do
 end;
 m:=0;
 for i:=1 to N do
  begin
   if a[m]=0
    then
     m:=m+1;
  end;
 l:=l+m+1;
writeln (l);
end.