#include <iostream>
using namespace std;
int main (){
int n, i, a=0;
cin >>n;
int h[n];
for(i=0;i<n;i++){
cin >> h[i];
}
for(i=0;i<n;i++){
if(h[i]==0){
a+=(h[i-1]*(h[i-1]<h[i+1])+h[i+1]*(h[i+1]<h[i-1])+h[i+1]*(h[i-1]==h[i+1]));
}
}
cout << a;
}