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;
    auto s = new long[](n + 1);
    foreach (i ; 1 .. n + 1) {
        s[i] = s[i - 1] + a[i - 1];
    }
    auto p = new long[][](2, n + 1);
    foreach (i ; 1 .. n + 1) {
        p[0][i] = s[i];
        if (a[i - 1] == 0) {
            p[0][i] = min(p[0][i], 2 + p[0][i - 1]);
        }
        else {
            p[0][i] = min(p[0][i], (a[i - 1] % 2 == 1) + p[0][i - 1]);
        }
        p[1][i] = min(s[i], (a[i - 1] % 2 == 0) + p[1][i - 1]);
    }

    auto sf = new long[][](2, n + 1);

    foreach_reverse (i ; 0 .. n) {
        sf[0][i] = s[n] - s[i];
        if (a[i] == 0) {
            sf[0][i] = min(sf[0][i], 2 + sf[0][i + 1]);
        }
        else {
            sf[0][i] = min(sf[0][i], (a[i] % 2 == 1) + sf[0][i + 1]);
        }
        sf[1][i] = min(s[n] - s[i], (a[i] % 2 == 0) + sf[1][i + 1]);
    }

    long ans = inf6;

    foreach (i ; 0 .. n + 1) {
        foreach (j ; 0 .. 2) {
            long t = p[j][i] + sf[j^1][i];
            ans = min(ans, t);
        }
    }

    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);
        }
    }
}
