      PROGRAM MaximalValue
      IMPLICIT NONE
      integer(16) :: n
      integer(16),allocatable :: a(:),b(:),a1(:),a2(:)
      integer(16) :: i
      
      read*,n
      allocate( a(n), b(n-1) )
      allocate( a1(n),a2(n) )
      read*,b(1:n-1)
      
      a1(1:n-1) = b(1:n-1)
      a2(2:n) = b(1:n-1)
      a1(n) = a2(n)
      a2(1) = a1(1)
     ! print*,a1
     ! print*,a2
      
      a = max( a1,a2 )
      !print*,a
      
      do i = n-1,1,-1
    !    print*,i,'i,b,max',b(i),max(a(i),a(i+1))
        if( b(i)/=max(a(i),a(i+1)) )then
          a(i+1) = min( a1(i),a2(i) )
        end if
        
        
      end do
      
      do i = 1,n-1
        if(b(i)/=max(a(i),a(i+1)) )then
          a(i) = min( a1(i),a2(i) )
        end if
      end do
      
  !    print*,a
      print*,sum(a)
      
      
      END PROGRAM