#include <cstdio>
#include <iostream>
#define MN 201000

int a[MN];
long long f[MN][3];
long long s[MN];

int main()
{
	int n; scanf("%d", &n);
	long long ans = 1e18;
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]), s[i] = s[i - 1] + a[i];
	for(int i = 1; i <= n; i++)
	{
		f[i][0] = std::min(f[i - 1][0], s[i - 1]) + (a[i] == 0 ? 2 : ((a[i] & 1) ? 1 : 0));
		f[i][1] = std::min(f[i - 1][0], std::min(f[i - 1][1], s[i - 1])) + (a[i] == 0 ? 1 : ((a[i] & 1) ? 0 : 1));
		f[i][2] = std::min(f[i - 1][1], f[i - 1][2]) + (a[i] == 0 ? 2 : ((a[i] & 1) ? 1 : 0));		
		ans = std::min(ans, std::min(std::min(f[i][0], f[i][1]), std::min(f[i][2], s[i])) + s[n] - s[i]);
	}
	printf("%lld\n", ans);
}