#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;

int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

int dp[5010][5];

signed main(){
    
    int n; cin >> n;
    vector<int> p(n);
    for(int i = 0; i < n; i++) cin >> p[i];
    
    for(int i = 0; i < 5010; i++) for(int j = 0; j < 5; j++) dp[i][j] = INF;

    dp[0][0] = 0;

    for(int i = 0; i < n; i++){
        for(int j = 0; j < 5; j++){
            for(int k = j; k <= p[i]; k++){
                int nj = p[i] - k;
                int cost = k;
                if(i != 0) cost *= 2;
                dp[i + 1][nj] = min(dp[i + 1][nj], dp[i][j] + cost);
            }
        }
    }
/*
    for(int i = 0; i <= n; i++){
        for(int j = 0; j < 4; j++){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
*/
    
    int ans = INF;
    for(int j = 0; j < 5; j++) ans = min(ans, dp[n][j] + j);
    cout << ans << endl;

    return 0;
}

