#pragma gcc optimize("Ofast")

#include "bits/stdc++.h"
using namespace std;
typedef int64_t lld;
typedef pair<int,int> pii;
typedef pair<lld,lld> pll;
typedef pair<int,pll> pip;
typedef pair<pll,int> ppi;
typedef pair<lld,pll> plp;
typedef pair<pll,lld> ppl;
typedef pair<pll,pll> ppp;
template<typename T>
using maxHeap = priority_queue<T,vector<T>,less<T>>;
template<typename T>
using minHeap = priority_queue<T,vector<T>,greater<T>>;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define endl '\n'
#define jizz cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
inline void input(int &_x) {
    _x = 0;
    int _tmp = 1; char _tc = getchar();
    while((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
    if(_tc == '-') _tc = getchar(), _tmp = -1;
    while(_tc >= '0' && _tc <= '9') _x = _x*10+(_tc-48), _tc = getchar();
    _x *= _tmp;
}
inline void output(int _x) {
    char _buff[20]; int _f = 0;
    if(_x == 0)putchar('0');
    while(_x > 0)
    {
        _buff[_f++] = _x%10+'0';
        _x /= 10;
    }
    for(_f-=1; _f >= 0; _f--)
        putchar(_buff[_f]);
    putchar('\n');
}
template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}
template<class T1,class T2>
ostream& operator<<(ostream& out, pair<T1,T2> p) {
    return out << '(' << p.first << ", " << p.second << ')';
}
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) {
     return _out(s,c.begin(),c.end());
 }
#ifdef erd1
    #define pprint(x) cerr<<__PRETTY_FUNCTION__<<":"<<__LINE__<<" - "<<(#x)<<"="<<(x)<<endl
#else
    #define pprint(x)
#endif

// code starts here
vector<lld> sv,sp,sz;
signed main(){
    int n;
    cin >> n;
    sv.pb(0);sp.pb(0);sz.pb(0);
    for(int i = 0; i < n; i++){
        lld x;
        cin >> x;
        sv.pb(sv.back()+x);
        sp.pb(sp.back()+x%2);
        sz.pb(sz.back()+!x);
    }
    // cout << sv << endl << sp << endl << sz << endl;
    // cout << "[";for(int i = 0; i <= n; i++)cout << (i?" ":"") << sv[i]-sp[i]-2*sz[i] ;cout << "]\n";
    // cout << "[";for(int i = 0; i <= n; i++)cout << (i?" ":"") << 2*sz[i]+2*sp[i]-i   ;cout << "]\n";
    // cout << "[";for(int i = 0; i <= n; i++)cout << (i?" ":"") << -2*sz[i]-2*sp[i]+i  ;cout << "]\n";
    // cout << "[";for(int i = 0; i <= n; i++)cout << (i?" ":"") << -sv[i]+sp[i]+2*sz[i];cout << "]\n";
    lld min1 = LLONG_MAX, min2 = LLONG_MAX, min3 = LLONG_MAX, min4 = LLONG_MAX;
    for(int i = 0; i <= n; i++){
        min4 = min(min4,
            (min3 = min(min3,
                (min2 = min(min2,
                    (min1 = min(min1,
                        sv[i]-sp[i]-2*sz[i]
                    )) + 2*sz[i]+2*sp[i]-i
                )) - 2*sz[i]-2*sp[i]+i
            )) - sv[i]+sp[i]+2*sz[i]
        );
        // cout << min1 << " " << min2 << " " << min3 << " " << min4 << endl;
    }
    cout << min4 + sv[n] << endl;
}
// 0 [a [b c) d) n
// ans = sum [0,a) + sum [d,n) + sum par [a,b) + sum par [c,d) + sum npar [b,c) + 2*cnt zero [a,b)+ 2*cntzero[c,d)
// ans = sv[a] + sv[n]-sv[d]+sp[b]-sp[a]+sp[d]-sp[c]+(sp[b]-sp[c]+c-b)+2*(cz[b]-cz[a]+cz[d]-cz[c])
// ans = (sv-sp-2*sz)[a] + (2*sz+2*sp-1)[b] + (-2*sz-2*sp+1)[c] + (-sv+sp+2*sz)[d] +sv[n]
// 0 1 2 3 4
// 1 0 2 3
// a = 2, b = 3, c = 4, d = 4, n = 4
// -2 + 1 + -2 + -2 + 6
// 1 + 0 + 0 + 0 + 0 + 0
// 1 + 6 - 6 + 1 - 1 + 2 - 2 + (1-2+4-3)+2*(1-1+1-1)
// (1-1-2*1) + (2*1+2*1-3) + (-2*2-2*1+4) + (-6+2+2*1) + 6


Measured memory_bytes: 5204