#include <iostream>
using namespace std;

#define INF ((unsigned long long)200000*200000)
unsigned long long A[200000] = {0};
unsigned long long dp[200001][5];


unsigned long long cost(int i, int k) {
	if (k==0 || k==4) return A[i];
	if (k==1 || k==3) {
		if (A[i]==0) return 2;
		if ((A[i]&0x1)==0) return 0;
		return 1;
	}
	if ((A[i]&0x1)==1) return 0;
	return 1;
}

int main(void) {
	int L;
	cin >> L;
	for (int i = 0; i < L; i++) cin >> A[i];

	for (int i = 0; i <= L; i++) {
		for (int j = 0; j < 5; j++) {
			dp[i][j] = INF;
		}
	}

	dp[0][0] = 0;
	for (int i = 0; i < L; i++) {
		for (int j = 0; j < 5; j++) {
			for (int k = j; k < 5; k++) {
				dp[i+1][k] = min(dp[i+1][k], dp[i][j] + cost(i, k));
			}
		}
	}

	unsigned long long ans = INF;
	for (int i = 0; i < 5; i++) {
		ans = min(ans, dp[L][i]);
	}
	cout << ans << endl;

	return 0;
}
