#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

typedef long long ll;

namespace rmq1 {
  const int N = 1 << 18;
  const ll INF = 2e18;
  ll data[2*N-1];
  void init(const vector<ll> &vs) {
    REP(i, N) {
      data[N-1+i] = INF;
    }
    int n = vs.size();
    REP(i, n) {
      data[N-1+i] = vs[i];
    }
    for(int i = N-2; i >= 0; --i) {
      data[i] = min(data[2*i+1], data[2*i+2]);
    }
  }
  ll getMinImpl(int bg, int ed, int k, int left, int right) {
    if(ed <= left || right <= bg) return INF;
    if(bg == left && ed == right) return data[k];
    int md = (left + right) / 2;
    if(ed <= md) return getMinImpl(bg, ed, 2*k+1, left, md);
    if(md <= bg) return getMinImpl(bg, ed, 2*k+2, md, right);
    ll lmin = getMinImpl(bg, md, 2*k+1, left, md);
    ll rmin = getMinImpl(md, ed, 2*k+2, md, right);
    return min(lmin, rmin);
  }
  ll getMin(int bg, int ed) {
    return getMinImpl(bg, ed, 0, 0, N);
  }
}
namespace rmq2 {
  const int N = 1 << 18;
  const ll INF = 2e18;
  ll data[2*N-1];
  void init(const vector<ll> &vs) {
    REP(i, N) {
      data[N-1+i] = INF;
    }
    int n = vs.size();
    REP(i, n) {
      data[N-1+i] = vs[i];
    }
    for(int i = N-2; i >= 0; --i) {
      data[i] = min(data[2*i+1], data[2*i+2]);
    }
  }
  ll getMinImpl(int bg, int ed, int k, int left, int right) {
    if(ed <= left || right <= bg) return INF;
    if(bg == left && ed == right) return data[k];
    int md = (left + right) / 2;
    if(ed <= md) return getMinImpl(bg, ed, 2*k+1, left, md);
    if(md <= bg) return getMinImpl(bg, ed, 2*k+2, md, right);
    ll lmin = getMinImpl(bg, md, 2*k+1, left, md);
    ll rmin = getMinImpl(md, ed, 2*k+2, md, right);
    return min(lmin, rmin);
  }
  ll getMin(int bg, int ed) {
    return getMinImpl(bg, ed, 0, 0, N);
  }
}
namespace rmq3 {
  const int N = 1 << 18;
  const ll INF = 2e18;
  ll data[2*N-1];
  void init(const vector<ll> &vs) {
    REP(i, N) {
      data[N-1+i] = INF;
    }
    int n = vs.size();
    REP(i, n) {
      data[N-1+i] = vs[i];
    }
    for(int i = N-2; i >= 0; --i) {
      data[i] = min(data[2*i+1], data[2*i+2]);
    }
  }
  ll getMinImpl(int bg, int ed, int k, int left, int right) {
    if(ed <= left || right <= bg) return INF;
    if(bg == left && ed == right) return data[k];
    int md = (left + right) / 2;
    if(ed <= md) return getMinImpl(bg, ed, 2*k+1, left, md);
    if(md <= bg) return getMinImpl(bg, ed, 2*k+2, md, right);
    ll lmin = getMinImpl(bg, md, 2*k+1, left, md);
    ll rmin = getMinImpl(md, ed, 2*k+2, md, right);
    return min(lmin, rmin);
  }
  ll getMin(int bg, int ed) {
    return getMinImpl(bg, ed, 0, 0, N);
  }
}


int L;
ll vs[200000+10];

int main(void) {
  scanf("%d", &L);
  ll sum = 0;
  REP(i, L) {
    scanf("%lld", &vs[i]);
    sum += vs[i];
  }
  
  vector<ll> rs(L+1, 0); // 右から折り返し
  for(int i = L-1; i >= 0; --i) {
    if(vs[i] == 0) {
      rs[i] = rs[i+1] + 2;
    } else if(vs[i] % 2 == 1) {
      rs[i] = rs[i+1] - vs[i] + 1;
    } else {
      rs[i] = rs[i+1] - vs[i];
    }
  }
  rmq1::init(rs);

  vector<ll> ls(L+1, 0); // 左から折り返し
  REP(i, L) {
    if(vs[i] == 0) {
      ls[i+1] = ls[i] + 2;
    } else if(vs[i] % 2 == 1) {
      ls[i+1] = ls[i] - vs[i] + 1;
    } else {
      ls[i+1] = ls[i] - vs[i];
    }
  }
  rmq2::init(ls);

  vector<ll> l1s(L+1, 0); // 左から片道
  REP(i, L) {
    if(vs[i] == 0) {
      l1s[i+1] = l1s[i] + 1;
    } else if(vs[i] % 2 == 1) {
      l1s[i+1] = l1s[i] - vs[i];
    } else {
      l1s[i+1] = l1s[i] - vs[i] + 1;
    }
  }

  vector<ll> lrs(L+1, 0); // 左から行って折り返して戻る
  lrs[0] = l1s[0] + rmq2::getMin(0, L+2);
  REP(i, L) {
    lrs[i+1] = l1s[i+1] + rmq2::getMin(i+1, L+2) - ls[i+1];
  }
  rmq3::init(lrs);

  ll res = 2e18;
  REP(i, L+1) {
    ll cur = sum;
    cur += rmq1::getMin(0, i+1) - rs[i];
    cur += rmq3::getMin(i, L+2) - l1s[i];
    res = min(cur, res);
  }
  
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 20352