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

immutable long INF = 1L << 59;

long even(long n) {
    return n == 0 ? 2 : n % 2;
}

long odd(long n) {
    return 1 - n % 2;
}

void main() {
    auto N = readln.chomp.to!int;
    auto A = N.iota.map!(_ => readln.chomp.to!long).array;

    auto dp = new long[][](N+1, 5);
    foreach (i; 0..N+1) dp[i][] = INF;

    dp[0][0] = 0;
    //foreach (i; 0..N) {
    //    dp[i+1][0] = dp[i][0] + A[i];
    //}

    foreach (i; 0..N) {
        long m = dp[i][0];
        dp[i+1][0] = min(dp[i+1][0], m + A[i]);

        m = min(m, dp[i][1]);
        dp[i+1][1] = min(dp[i+1][1], m + even(A[i]));

        m = min(m, dp[i][2]);
        dp[i+1][2] = min(dp[i+1][2], m + odd(A[i]));

        m = min(m, dp[i][3]);
        dp[i+1][3] = min(dp[i+1][3], m + even(A[i]));

        m = min(m, dp[i][4]);
        dp[i+1][4] = min(dp[i+1][4], m + A[i]);
    }

    dp[N].reduce!min.writeln;
}
