#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
      }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

const int MAX = 300000;
int a[MAX], rui[MAX], r1[2][MAX], r2[MAX], loss1[MAX], loss[2][MAX], loss3[2][MAX], n;
int solve(int idx){
  rep(i,n+10){
    rui[i] = r2[i] = loss1[i] = 0;
  }
  rrep(i,n)rui[i] += rui[i-1]+a[i];
  rrep(i,n){
    r2[i] += r2[i-1];
    if(a[i] < 2){r2[i] += 2-a[i];continue;}
    if(a[i]%2 == 1)r2[i] += 1;
  }
  rep(i,n+1)loss1[i] = rui[n]-rui[i]+r2[i];
  drep(i,n-1,0)loss1[i] = min(loss1[i+1], loss1[i]);
  rep(i,n+1)loss[idx][i] = loss1[i]-r2[i];
  return 0;
}

signed main(){
  scanf("%lld%", &n);
  rrep(i,n)scanf("%lld", &a[i]);
  solve(0);
  rrep(i,n/2)swap(a[i], a[n-i+1]);
  solve(1);
  rrep(i,n/2)swap(a[i], a[n-i+1]);
  rep(i,n/2)swap(loss[1][i], loss[1][n-i]);
  
  rrep(i,n){
    r1[0][i] = r1[0][i-1];
    if(a[i]%2 == 0)r1[0][i] += 1;
  }
  drep(i,n-1,0){
    r1[1][i] = r1[1][i+1];
    if(a[i]%2 == 0)r1[1][i] += 1;
  }
  rep(i,2)rep(j,n+1)loss3[i][j] = loss[i][j] + r1[i][j];
  drep(i,n-1,0)loss3[0][i] = min(loss3[0][i], loss3[0][i+1]);
  rrep(i,n)loss3[1][i] = min(loss3[1][i], loss3[1][i-1]);
  int ans = INF;
  rep(i,n+1)chmin(ans, loss[1][i] + loss3[0][i]-r1[0][i]);
  drep(i,n,0)chmin(ans, loss[0][i] + loss3[1][i]-r1[1][i]);
  
  printf("%lld\n", ans);
  return 0;
}






Measured memory_bytes: 22400