#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
using namespace std;

int main(){

	int N,ans = BIG_NUM;

	scanf("%d",&N);

	int* table = new int[N+1];

	int** dp = new int*[N+1];
	for(int i = 0; i <= N; i++){
		dp[i] = new int[4];
		for(int k = 0; k <= 3; k++)dp[i][k] = BIG_NUM;
	}

	for(int i = 0; i < N; i++){
		scanf("%d",&table[i+1]);
	}

	for(int i = 0; i <= table[1]; i++){
		dp[1][table[1] - i] = i;
	}

	for(int right = 2; right <= N; right++){
		for(int left_rest = 0; left_rest <= 3; left_rest++){
			if(dp[right-1][left_rest] == BIG_NUM)continue;
			for(int i = left_rest; i <= max(left_rest,table[right]);i++){
				dp[right][max(0,table[right]-i)] = min(dp[right][max(0,table[right]-i)],
						dp[right-1][left_rest]+2*i);
			}
		}
	}

	for(int i = 0; i <= table[N]; i++){
		ans = min(ans,dp[N][i] + i);
	}

	printf("%d\n",ans);

   return 0;
}