#include<bits/stdc++.h>
#define ll long long
#define rg register
using namespace std;
const int MAXN=2e5+10;
ll Ans,n,Seq[MAXN],Pre[MAXN],Odd[MAXN],Even[MAXN];
ll Dp[MAXN][4];
inline ll Min(rg ll A,rg ll B){   return A<B?A:B;   }
int main()
{   memset(Dp,0X7f,sizeof(Dp));
	scanf("%lld",&n),Dp[0][0]=0;
	for(rg int i=1;i<=n;i++) scanf("%lld",&Seq[i]),Ans+=Seq[i];
	for(rg int i=1;i<=n;i++) Odd[i]=(Seq[i]&1),Even[i]=(Seq[i]&&(~Seq[i]&1));
	for(rg int i=1;i<=n;i++)
	{	Dp[i][0]=Dp[i-1][0]+Seq[i];
		Dp[i][1]=Min(Dp[i-1][1],Dp[i-1][0])+(Seq[i]?!Even[i]:2);
		Dp[i][2]=Min(Dp[i-1][2],Min(Dp[i-1][1],Dp[i-1][0]))+(!Odd[i]);
		Dp[i][3]=Min(Dp[i-1][3],Min(Dp[i-1][2],Min(Dp[i-1][1],Dp[i-1][0])))+(Seq[i]?!Even[i]:2);
	}
	for(rg ll i=n,Sum=0;i>=1;i--) Ans=Min(Ans,Min(Dp[i][3],Dp[i][2])+Sum),Sum+=Seq[i];
	printf("%lld\n",Ans);
}
