#include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

int main(){
	int n; cin >> n; std::vector<int> p(n + 2);
	for(int i = 1; i <= n; i++) cin >> p[i];
	
	std::vector<std::vector<int>> dp(n + 3, std::vector<int>(4, (1 << 30)));
	for(int i = 0; i < 4; i++) dp[0][i] = i;
	for(int i = 0; i <= n; i++) {
		for(int j = 0; j < 4; j++) {
			for(int k = 0; k < 4; k++) {
				if(j + k < p[i + 1]) continue;
				int tmp = (i == n - 1 ? 1 : 2);
				
				dp[i + 1][k] = std::min(dp[i + 1][k], dp[i][j] + tmp * k);
			}
		}
	}
	
	cout << std::min({dp[n][0], dp[n][1], dp[n][2], dp[n][3]}) << endl;
	return 0;
}

