#include <bits/stdc++.h>

using namespace std;

using i64 = int64_t;

const i64 INF = 1e18 + 7;

signed main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(auto& x : a)
        cin >> x;
    vector<vector<i64>> dp(n, vector<i64>(4, INF));
    for(int i = 0; i < 4; ++i)
        dp[0][i] = i;
    for(int i = 0; i < n - 1; ++i){
        for(int j = 0; j < 4; ++j){
            int mi = max(0, a[i] - j);
            for(int k = mi; k < 4; ++k)
                dp[i + 1][k] = min(dp[i + 1][k], dp[i][j] + k * 2);
        }
    }
    i64 ans = INF;
    for(int i = 0; i < 4; ++i)
        ans = min(ans, dp.back()[i] + max(0, a.back() - i));
    cout << ans << endl;
}

