import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int n;
    scan(n);
    auto a = iota(n).map!(i => readln.chomp.to!int).array;

    // 0: 無, 1: 偶(!= 0), 2: 奇, 3: 偶(!= 0), 4: 無
    auto dp = new long[][](n + 1, 5);

    foreach (i ; 1 .. n + 1) {
        foreach (j ; 0 .. 5) {
            dp[i][j] = inf6;
            foreach (k ; 0 .. j + 1) {
                dp[i][j] = min(dp[i][j], dp[i - 1][k]);
            }
            if (j == 0 || j == 4) {
                dp[i][j] += a[i - 1];
            }
            else if (j == 1 || j == 3) {
                if (a[i - 1] == 0) {
                    dp[i][j] += 2;
                }
                else {
                    dp[i][j] += (a[i - 1] % 2);
                }
            }
            else {
                dp[i][j] += (a[i - 1] % 2 == 0);
            }
        }
    }

    long ans = inf6;
    foreach (i ; 0 .. 5) {
        ans = min(ans, dp[n][i]);
    }
    writeln(ans);
}










void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}
