#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 200010
ll a[N],b[N],c[N],d[N],e[N],f[N],n;
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
    b[i]=c[i]=d[i]=e[i]=f[i]=1e17;
  }
  b[0]=0;
  for(int i=0;i<n;i++){
    ll xs,ys;
    if(a[i]==0)xs=2,ys=1;
    else if(a[i]%2==1)xs=1,ys=0;
    else xs=0,ys=1;
    b[i+1]=b[i]+a[i];
    c[i+1]=min(b[i],c[i])+xs;
    d[i+1]=min(min(b[i],c[i]),d[i])+ys;
    e[i+1]=min(d[i],e[i])+xs;
    f[i+1]=min(min(c[i],d[i]),min(e[i],f[i]))+a[i];
  }
  ll ans=min(min(b[n],c[n]),min(min(d[n],e[n]),f[n]));
  cout<<ans<<endl;
  return 0;
}
