#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;
template <class T>
inline void read(T &x)
{
    x=0; char c=getchar();  int f=1;
    while(!isdigit(c)){if(c=='-')f=-1; c=getchar();}
    while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int N=2e5+10;
ll pre[N][5];
int n,a[N];
int main()
{
//	freopen("in.txt","r",stdin);
	read(n);
	for(int i=1;i<=n;++i) read(a[i]);
	ll ans=1e18;
	for(int i=1;i<=n;++i)
	{
		pre[i][0]=pre[i-1][0];
		for(int j=1;j<5;++j) pre[i][j]=min(pre[i][j-1],pre[i-1][j]);
		pre[i][0]+=a[i];
		pre[i][1]+=(a[i]==0?2:a[i]%2);
		pre[i][2]+=(a[i]%2==0);
		pre[i][3]+=(a[i]==0?2:a[i]%2);
		pre[i][4]+=a[i];
	}
	for(int j=0;j<5;++j) ans=min(ans,pre[n][j]);
	printf("%lld",ans);
	return 0;
}	