import std.stdio, std.conv, std.math, std.string, std.range, std.array, std.algorithm, std.typecons;

void main(){
    immutable L = readln().strip().to!int();
    int[] a;
    a.length = L;

    foreach(immutable int i; 0 .. L) {
        a[i] = readln().strip().to!int();
    }

    long[5][] dp;
    dp.length = L;

    dp[0][0] = a[0];
    if(a[0] == 0) {
        dp[0][1] = long.max/2;
        dp[0][2] = long.max/2;
        dp[0][3] = long.max/2;
    } else {
        dp[0][1] = a[0] % 2;
        dp[0][2] = (a[0] + 1) % 2;
        dp[0][3] = a[0] % 2;
    }
    dp[0][4] = a[0];

    for (size_t i = 1; i < L; ++i) {
        dp[i][0] = dp[i-1][0] + a[i];
        if(a[i] == 0) {
            dp[i][1] = long.max/2;
            dp[i][2] = long.max/2;
            dp[i][3] = long.max/2;
        } else {
            dp[i][1] = min(dp[i-1][0], dp[i-1][1]) + a[i] % 2;
            dp[i][2] = min(dp[i-1][0], dp[i-1][1], dp[i-1][2]) + (a[i] + 1) % 2;
            dp[i][3] = min(dp[i-1][0], dp[i-1][1], dp[i-1][2], dp[i-1][3]) + a[i] % 2;
        }
        dp[i][4] = min(dp[i-1][1], dp[i-1][2], dp[i-1][3], dp[i-1][4]) + a[i];
    }

    writeln(dp[L-1].reduce!min);
}
