program abc140c
  implicit none
  integer :: n
  integer,dimension(:),allocatable :: a, b, c
  read *, n
  n = n - 1
  allocate(c(n))
  read *, c
  a = [c(1),c]
  b = [c,c(n)]
  print *, sum(merge(a,b,a<b))
end program abc140c
