#include<bits/stdc++.h>
#define ll long long
#define INF 1e18
using namespace std;
template <typename T> void read(T &x){
	x=0;char c=getchar();int fh=1;
	while (!isdigit(c)){if (c=='-')fh=-1;c=getchar();}
	while (isdigit(c))x=x*10+c-'0',c=getchar();
	x*=fh;
}
ll n,x,dp[200010][5],a[200010];
int main(){
	read(n);
	for (int i=1;i<=n;i++) read(a[i]);
	for (int i=0;i<=n+1;i++)
		for (int j=0;j<=4;j++) dp[i][j]=INF;
	dp[0][0]=0;
	for (int i=1;i<=n+1;i++){
		for (int j=0;j<=4;j++){
			for (int k=0;k<=j;k++) dp[i][j]=min(dp[i][j],dp[i-1][k]);
			if (abs(j-2)<=1){
				if (a[i]%2==j%2) dp[i][j]++;
				if (a[i]==0&&j%2==1)dp[i][j]+=2;
			}else{
				dp[i][j]+=a[i];
			}
		}
	}
	cout<<dp[n+1][4]<<endl;
	return 0;
}