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

const int L = 2e5 + 5;
long long dp[L][5];

long long mdp(int i, int j) {
	if(i == 0) return 0;
	long long dr = dp[i][0];
	for(int ii = 1; ii <= j; ++ii)
		dr = min(dr, dp[i][ii]);
	return dr;
}

int l, a[L];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> l;
	for(int i = 1; i <= l; ++i) {
		cin >> a[i];
	}
	for(int i = 1; i <= l; ++i) {
		dp[i][0] = mdp(i - 1, 0) + a[i];
		dp[i][1] = mdp(i - 1, 1) + (a[i] == 0 ? 2 : (a[i] & 1));
		dp[i][2] = mdp(i - 1, 2) + (a[i] & 1 ^ 1);
		dp[i][3] = mdp(i - 1, 3) + (a[i] == 0 ? 2 : (a[i] & 1));
		dp[i][4] = mdp(i - 1, 4) + a[i];
	}
	cout << mdp(l, 4) << endl;
	return 0;
}
