#include <bits/stdc++.h>
using namespace std;

const int N = 200005, INF = int(1e9);

int n, a[N], d[N][5];

int c(int x, int y){
    if(y == 2) return (a[x] % 2 == 0);
    if(y == 1 || y == 3) return 2 * !a[x] + (a[x] % 2);
    return a[x];
}

int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) scanf("%d", a + i);
    for(int i = 1; i <= n; i++){
        int t = INF;
        for(int j = 0; j < 5; j++){
            t = min(t, d[i - 1][j]);
            d[i][j] = t + c(i, j);
        }
    }
    printf("%d\n", *min_element(d[n], d[n] + 5));
}