#include<iostream>
#include<string>
#include<set>
#include<utility>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
#include<stack>
#include<iomanip>

#define P pair<int, int>

typedef long long ll;

using namespace std;


int main() {
	int N;
	cin >> N;
	vector<int> p(N);
	for (int i = 0; i < N; i++) {
		cin >> p[i];
	}

	int ans = 1e9;
	for (int i = 0; i <= 3; i++) {
		int from = i;
		int cnt = i;
		for (int j = 0; j < N; j++) {
			int plus = max(0, p[j] - from);
			cnt += (j == N - 1 ? 1 : 2)*plus;
			from = plus;
		}
		ans = min(ans, cnt);
	}

	cout << ans << endl;


	return 0;
}
