#include<iostream>
#include<algorithm>
using namespace std;


int main(){
    int N;
    cin>>N;
    int p[5000];
    for(int i = 0;i < N;i++)cin>>p[i];
    int min_sum = 20000;
    for(int i = 0;i <= p[0];i++){
        int q[5000];
        for(int j = 0;j < N;j++){
            q[j] = p[j];
        }
        int sum= i;
        q[0] -= i;
        for(int j= 0;j <= N-2;j++){
            if(q[j] <= 0)continue;

            sum+=q[j]*2;
            q[j+1] -= q[j];
        }

        if(q[N-1]>0)sum += q[N-1];
        min_sum = min(min_sum,sum);
    }
    cout<<min_sum<<endl;
    return 0;
}
