#include <bits/stdc++.h>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a(n), aa(n);
	for(int i=0; i<n; ++i) cin >> a[i], aa[i] = a[i];
	
	int ans = 1e9;
	for(int j=0; j<=a[0]; ++j) {
		// cout << j << endl;
		int ret = j;
		a[0] -= j;
		for(int i=1; i<n-1; ++i) {
			while(a[i]>0) {
				if(a[i-1] > 0) {
					a[i-1]--;
					a[i]--;
					ret += 2;
				} else {
					a[i]--;
					a[i+1]--;
					ret += 2;
				}
			}
		}
		ret += max(0, a[0]) + max(0, a[n-1]);
		// cout << ret << endl;
		for(int i=0; i<n; ++i) a[i] = aa[i];
		ans = min(ans, ret);
	}
	
	cout << ans << endl;
	
	return 0;
}
