#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
using std::cin; using std::cout;
using std::endl;
using std::bitset; using std::map;
using std::queue; using std::priority_queue;
using std::set; using std::string;
using std::stringstream; using std::vector;
using std::pair; using std::make_pair;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<ULL, ULL> puu;
#ifdef DEBUG
using std::cerr;
#define pass cerr << "[" << __FUNCTION__ << "] : line = " << __LINE__ << endl;
#define display(x) cerr << #x << " = " << x << endl;
#define displaya(a, st, n)                                                     \
  {                                                                            \
    cerr << #a << " = {";                                                      \
    for (int qwq = (st); qwq <= (n); ++qwq)                                    \
      if (qwq == (st))                                                         \
        cerr << a[qwq];                                                        \
      else                                                                     \
        cerr << ", " << a[qwq];                                                \
    cerr << "}" << endl;                                                       \
  }
#define displayv(a) displaya(a, 0, (int)(a.size() - 1))
#include <ctime>
class MyTimer {
    clock_t st;
public:
    MyTimer() { cerr << std::fixed << std::setprecision(0); reset(); }
    ~MyTimer() { report(); }
    void reset() { st = clock_t(); }
    void report() {  cerr << "Time consumed: " << (clock() - st) * 1e3 / CLOCKS_PER_SEC << "ms" << endl; }
} myTimer;
#else
#define cerr if(false) std::cout
#define pass ;
#define display(x) ;
#define displaya(a, st, n) ;
#define displayv(a) ;
class MyTimer {
public: void reset() {} void report() {}
} myTimer;
#endif

template<typename A, typename B>
std::ostream& operator << (std::ostream &cout, const pair<A, B> &x) {
    return cout << "(" << x.first << ", " << x.second << ")";
}
template<typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) { return a > b ? a = b, true : false; }
template<typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) { return a < b ? a = b, true : false; }

const int maxN = 200000 + 233;
const LL maxA = 1000000000 + 233;
int n;
LL a[maxN], f[maxN][5];

int main() {
    scanf("%d", &n);
    for(int i = 1; i <= n; ++ i) scanf("%lld", a + i);
    LL ans = maxA * maxN;
//    memset(f, 0x3f, sizeof(f));
//    for(int j = 0; j < 5; ++ j) f[0][j] = 0;
//    for(int i = 1; i <= n; ++ i) {
//        f[i][0] = f[i - 1][0] + a[i];
//        f[i][1] = f[i - 1][1] + (a[i] % 2 == 0);
//        f[i][2] = f[i - 1][2] + (a[i] == 0 ? 2 : (a[i] % 2 == 1));
//        f[i][3] = f[i - 1][3] + (a[i] % 2 == 0);
//        f[i][4] = f[i - 1][4] + a[i];
////        displaya(f[i], 0, 4);
//        for(int j = 1; j < 5; ++ j) chmin(f[i][j], f[i][j - 1]);
//    }
//    ans = f[n][4];
    
    memset(f, 0x3f, sizeof(f));
    for(int j = 0; j < 5; ++ j) f[0][j] = 0;
    for(int i = 1; i <= n; ++ i) {
        f[i][0] = f[i - 1][0] + a[i];
        f[i][1] = f[i - 1][1] + (a[i] == 0 ? 2 : (a[i] % 2 == 1));
        f[i][2] = f[i - 1][2] + (a[i] % 2 == 0);
        f[i][3] = f[i - 1][3] + (a[i] == 0 ? 2 : (a[i] % 2 == 1));
        f[i][4] = f[i - 1][4] + a[i];
//        displaya(f[i], 0, 4);
        for(int j = 1; j < 5; ++ j) chmin(f[i][j], f[i][j - 1]);
    }
    chmin(ans, f[n][4]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9600