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

int n;

int calc(vector< int > p) {
    int sum = 0;
    for(int i = 1; i < n; i++) {
        if(p[i] > 0) {
            sum += p[i] * 2;
            p[i + 1] = max(0, p[i + 1] - p[i]);
        }
    }
    return sum + p[n];
}

int main() {

    vector< int > p;
    cin >> n;
    p.resize(n + 2);
    for(int i = 1; i <= n; i++) {
        cin >> p[i];
    }
    p[0] = p[n + 1] = 0;

    int sum = 100000000;
    for(int i = 0; i <= 3; i++) {
        sum = min(sum, calc(p) + i);
        p[1] = max(0, p[1] - 1);
    }
    cout << sum << endl;
}