#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std;

const int N=200010;
int n,a[N];
ll ans,sm1[N],sm2[N],sm3[N],mn1[N],mn2[N],mn3[N];

int main(){
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",&a[i]),ans+=a[i];
	rep(i,1,n) sm1[i]=sm1[i-1]+a[i];
	rep(i,1,n) sm2[i]=sm2[i-1]+((a[i]&1)?1:(a[i]?0:2));
	rep(i,1,n) sm3[i]=sm3[i-1]+(!(a[i]&1));
	rep(i,1,n) mn1[i]=min(mn1[i-1],sm1[i]-sm2[i]);
	rep(i,1,n) mn2[i]=min(mn2[i-1],sm2[i]+mn1[i]-sm3[i]);
	rep(i,1,n) mn3[i]=min(mn3[i-1],sm3[i]+mn2[i]-sm2[i]);
	rep(i,0,n) ans=min(ans,sm2[i]+mn3[i]+sm1[n]-sm1[i]);
	printf("%lld\n",ans);
	return 0;
}