#include<stdio.h>
#include<stdlib.h>
int main(void){
int n,h[100],i,sum=0;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&h[i]);}
if(h[0]==0){
sum=sum+h[1];}
for(i=1;i<n-1;i++){
if(h[i]==0){
if(h[i-1]<h[i+1]){
sum=sum+h[i-1];}
else{
sum=sum+h[i+1];}
}
}
if(h[n-1]==0){
sum=sum+h[n-2];}
printf("%d",sum);
}