#include <iostream>
#include <vector>
using namespace std;

#define int long long
const int INF = 1LL << 60;


int cost(int i, int s, const vector<int> &A){
    if(s == 0 || s == 4) return A[i];
    else if(s == 1 || s == 3){
        if(A[i] % 2 == 0) return (A[i] == 0 ? 2 : 0);
        else return 1;
    }else{
        if(A[i] % 2 == 0) return 1;
        else return 0;
    }
}

signed main() {

    int L; cin >> L;
    vector<int> A(L);
    for(int i = 0; i < L; i++) cin >> A[i];

    vector<vector<int> > dp(L + 1, vector<int> (5, INF));
    dp[0][0] = 0;
    for(int i = 0; i < L; i++){
        for(int j = 0; j < 5; j++){
            for(int k = j; k < 5; k++){
                dp[i + 1][k] = min(dp[i + 1][k], dp[i][j] + cost(i, k, A));
            }
        }
    }

    int ans = INF;
    for(int j = 0; j < 5; j++) ans = min(ans, dp[L][j]);
    cout << ans << endl;
    return 0;
}
