#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring> 
#include<cassert>
#include<cmath>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
long long a[200005];
long long dp[200005][5];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n;i++){
		dp[i][0]=dp[i-1][0]+a[i];
		dp[i][1]=min(dp[i-1][0],dp[i-1][1])+((a[i]==0)?2:(a[i]%2));
		dp[i][2]=min(dp[i-1][1],dp[i-1][2])+((a[i]==0)?1:(a[i]+1)%2);
		dp[i][3]=min(dp[i-1][2],dp[i-1][3])+((a[i]==0)?2:(a[i]%2));
		dp[i][4]=min(dp[i-1][3],dp[i-1][4])+a[i];
		for(int j=1;j<=4;j++) dp[i][j]=min(dp[i][j],dp[i][j-1]);
	}
	cout<<dp[n][4];
}