program Azadacha;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
     k,i,n:Integer;
     a:array [1..100] of Integer;
begin
 Readln(n);
  for i:=1 to n do
  begin
    Read(a[i]);
  end;
  for i:=1 to n do
  begin
   if (a[i]=a[i-1]) and (a[i-1]>0) then
   k:=k+a[i];
   a[i-2]:=a[i-2]-1;
  end;

  Writeln(k+6);
  Readln(n);
end.
