#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

#define Maxn 200005

long long n, a[Maxn], dp[Maxn][3], sum, ans;

int main() {
	register int i;
	scanf("%lld", &n);
	memset(dp, 0x3f, sizeof(dp));
	for (dp[0][0] = 0, i = 1; i <= n; i ++) {
		scanf("%lld", a + i);
		dp[i][0] = min(dp[i - 1][0], sum) + (a[i] & 1 ? 1 : (a[i] ? 0 : 2));
		dp[i][1] = min(dp[i - 1][1], dp[i - 1][2]) + (a[i] & 1 ? 1 : (a[i] ? 0 : 2));
		dp[i][2] = min(dp[i - 1][0], min(dp[i - 1][2], sum)) + (a[i] & 1 ? 0 : 1);
		sum += a[i];
	}
	for (sum = 0, ans = 1e18, i = n; i >= 0; i --)
		ans = min(ans, min({dp[i][0], dp[i][1], dp[i][2]}) + (sum += a[i + 1]));
	printf("%lld\n",ans);
	return 0;
}