#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n ;
int i, sum;
int h[n+2];
h[0]=101;
h[n+1]=101;//0<=h[i]<=100
for (i=1; i<=n; i++){
cin >> h[i] ;
}
for(i=1; i<=n;i++){
if (h[i]==0){
if(h[i-1]>=h[i+1]){
sum=sum+h[i+1];
}
else{
sum=sum+h[i-1];
}
}
}
cout << sum;
return 0;
}