/*Bismillahir Rahmanir Rahim*///{
#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std; using __gnu_cxx::power;
using ll = long long; using ull = unsigned long long; using ld = long double;
const ll llinf = (1ll<<61)-1;
const double eps = 1e-6, ldeps = 1e-9;
struct Dbg {
static constexpr auto &os = cout;   // replace by cerr in interactive.
template<class C> static auto dud(C *x)->decltype(os << *x, 0);
template<class C> static char dud(...);
template<class C> typename enable_if<sizeof dud<C>(0)!=1, Dbg&>::type operator<<(const C &x) { os << x; return *this; }
template<class C> Dbg &dump(C b, C e) {
    *this << "\n[";
    int cur = 0;
    for (C i = b; i!=e and cur<26; i++, cur++) *this << ", "+2*(i==b) << *i;
    return *this << ']';
}
template<class C> typename enable_if<sizeof dud<C>(0)==1, Dbg&>::type operator<<(const C &x) {
    return dump(begin(x), end(x));
}
template<class C, size_t X> typename enable_if<!is_same<C, const char>::value, Dbg&>::type operator <<(C (&x)[X]) {
    return dump(begin(x), end(x));
}
template<class B, class C> Dbg &operator <<(const pair<B, C> &x) {
    return *this << '{' << x.first << ", " << x.second << '}';
}
Dbg &operator<<(ostream&(*x)(std::ostream&)) { os << x; return *this; }
} dbg;
void err(istringstream *iss) { delete iss; }
template<class C, class... Args> void err(istringstream *iss, const C &val, const Args &... args) {
    string name; *iss >> name; if (name.back()==',') name.pop_back();
    dbg << name << " = " << val << "; ", err(iss, args...);
}
#define bug(args...) dbg << __LINE__ << ": ", err(new istringstream(#args), args), dbg << endl
#define cbug(a, args...) if (a) bug(args);
#define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b));
#define sl(a) int(strlen(a))
#define sz(a) int(a.size())
int T, Q, cn;//}
const int inf = 1000000007, mxn = 200005;

int n, a[mxn];

int memo[6][mxn];
bitset<mxn> vstd[6];
int dp(int state, int at) {
    if (at == n+1) return 0;
    auto &ret = memo[state][at];
    if (vstd[state][at]) return ret;
    vstd[state][at] = 1;
    ret = min((state < 4 ? dp(state+1, at) : inf), (state==1 or state==3 ? (a[at] ? (a[at]&1) : 2) : state==2 ? !(a[at]&1) : a[at])+dp(state, at+1));
    return ret;
}

signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    /*ll mn = 0;
    for (int i = 1; i <= n; i++) {
        mn += a[i];
    }
    for (int i = 1; i <= n; i++) {
        for (int j = i; j <= n; j++) {
            ll o = 0, os = 0;
            for (int k = i; k <= j; k++) {
                o += a[k]&1;
            }
            for (int k = 1; k <= i-1; k++) {
                os += a[k];
            }
            for (int k = j+1; k <= n; k++) {
                os += a[k];
            }
            mn = min(mn, o+os);
            for (int k = i; k <= j; k++) {
                for (int l = k; l <= j; l++) {
                    o = 0;
                    for (int m = k; m <= l; m++) {
                        o += !(a[m]&1);
                    }
                    for (int m = i; m <= k-1; m++) {
                        o += a[m] ? (a[m]&1) : 2;
                    }
                    for (int m = l+1; m <= j; m++) {
                        o += a[m] ? (a[m]&1) : 2;
                    }
                    mn = min(mn, o+os);
                }
            }
        }
    }
    cout << mn << '\n';*/

    cout << dp(0, 1) << '\n';
}

Measured memory_bytes: 14464