#include <bits/stdc++.h>
using namespace std;
const int maxn = 234567;
long long f[5][maxn];
long long a[maxn];
int main(){
	int n; cin >> n;
	for(int j = 0; j < 5; j++) f[j][0] = 1ll<<50;
	f[0][0] = 0;
	f[1][0] = 0;
	f[2][0] = 0;
	for(int i = 0; i < n; i++){
		int x; cin >> x;
		f[0][i + 1] = f[0][i] + x;
		f[1][i + 1] = min(f[1][i], f[0][i]) + (x%2) + (x == 0 ? 2 : 0);
		f[2][i + 1] = min(min(f[2][i], f[1][i]), f[0][i]) + 1 - (x%2);
		f[3][i + 1] = min(min(f[1][i], f[0][i]), min(f[2][i], f[3][i])) + (x%2) + (x == 0 ? 2 : 0);
		f[4][i + 1] = min(min(f[4][i], f[3][i]), min(f[2][i], min(f[1][i], f[0][i]))) + x;
	}
	cout << min(f[3][n], min(f[4][n], f[2][n])) << endl;
	return 0;
}
