#include<bits/stdc++.h>
using namespace std;
#define FOR(i,N) for(i=0;i<N;i++)
#define N 5
#define INF 1e9
typedef long long ll;
ll L;

ll cost(ll num, int s){
  ll cost;
  if( s == 0 || s == 4){
    cost = num;
  }else if ( s == 1 || s == 3 ){
    if (num == 0) cost = 2;
    else if(num % 2 == 0) cost = 0;
    else cost = 1;
  }else{
    if(num % 2 == 0) cost = 1;
    else cost = 0;
  }
  return cost;
}

int main(void){
  cin >> L;
  int i,j,k;
  vector<ll> A(L);
  FOR(i,L) cin >> A[i];

  ll dp[L+1][N];

  FOR(i,L) FOR(j,N) dp[i+1][j] = INF;
  FOR(j,N) dp[0][j] = 0;


  FOR(i,L){
    FOR(j,N){
      for(k = j; k < N; k++){
        dp[i+1][k] = min(dp[i+1][k], dp[i][j] + cost(A[i],k));
      }
    }
  }

  ll res = INF;
  FOR(j,N) res = min(res,dp[L][j]);
  cout << res << endl;
  return 0;
}