#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int main(){
	int L; cin >> L;
	vector<LL> A(L);
	repp(i,0,L) cin >> A[i];
	vector<LL> dp(5,0);
	repp(i,0,L){
		vector<LL> nx(5,1e9+7);
		LL z = dp[0];
		nx[0] = z+A[i];
		z = min(z,dp[1]);
		nx[1] = z+(A[i]==0?2:(A[i]%2==0?0:1));
		z = min(z,dp[2]);
		nx[2] = z+(A[i]%2==1?0:1);
		z = min(z,dp[3]);
		nx[3] = z+(A[i]==0?2:(A[i]%2==0?0:1));
		z = min(z,dp[4]);
		nx[4] = z+A[i];
		swap(nx,dp);
	}
	repp(i,1,5) dp[0] = min(dp[0],dp[i]);
	cout << dp[0] << endl;
	return 0;
}
