#https://atcoder.jp/contests/yahoo-procon2019-qual/tasks/yahoo_procon2019_qual_d

#2019-02-10



#DP



L = int(eval(input()))

A = [int(eval(input())) for i in range(L)]



DP = [[0 for i in range(5)] for j in range(L+1)]



def cost(s, a):

    if s == 0 or s == 4:

        return a

    elif s == 1 or s == 3:

        if a > 0:

            return a%2

        else:

            return 2

    else:

        return (a+1)%2



for i in range(L):

    a = A[i]

    DP[i+1][0] = min(DP[i][:1]) + cost(0, a)

    DP[i+1][1] = min(DP[i][:2]) + cost(1, a)

    DP[i+1][2] = min(DP[i][:3]) + cost(2, a)

    DP[i+1][3] = min(DP[i][:4]) + cost(3, a)

    DP[i+1][4] = min(DP[i][:5]) + cost(4, a)







print((min(DP[L])))
#https://atcoder.jp/contests/yahoo-procon2019-qual/tasks/yahoo_procon2019_qual_d

#2019-02-10



#DP



L = int(eval(input()))

A = [int(eval(input())) for i in range(L)]



DP = [0 for i in range(5)]



def cost(s, a):

    if s == 0 or s == 4:

        return a

    elif s == 1 or s == 3:

        if a > 0:

            return a%2

        else:

            return 2

    else:

        return (a+1)%2



for i in range(L):

    n = [min(DP[:i+1]) for i in range(5)]

    a = A[i]

    DP[0] = n[0] + cost(0, a)

    DP[1] = n[1] + cost(1, a)

    DP[2] = n[2] + cost(2, a)

    DP[3] = n[3] + cost(3, a)

    DP[4] = n[4] + cost(4, a)







print((min(DP)))
# https://atcoder.jp/contests/yahoo-procon2019-qual/tasks/yahoo_procon2019_qual_d
# 2019-02-10
# DP
L = int(eval(input()))
A = [int(eval(input())) for i in range(L)]
DP = [[0 for i in range(5)] for j in range(L + 1)]


def cost(s, a):
    if s == 0 or s == 4:
        return a
    elif s == 1 or s == 3:
        if a > 0:
            return a % 2
        else:
            return 2
    else:
        return (a + 1) % 2


for i in range(L):
    a = A[i]
    DP[i + 1][0] = min(DP[i][:1]) + cost(0, a)
    DP[i + 1][1] = min(DP[i][:2]) + cost(1, a)
    DP[i + 1][2] = min(DP[i][:3]) + cost(2, a)
    DP[i + 1][3] = min(DP[i][:4]) + cost(3, a)
    DP[i + 1][4] = min(DP[i][:5]) + cost(4, a)
print((min(DP[L])))

# https://atcoder.jp/contests/yahoo-procon2019-qual/tasks/yahoo_procon2019_qual_d
# 2019-02-10
# DP
L = int(eval(input()))
A = [int(eval(input())) for i in range(L)]
DP = [0 for i in range(5)]


def cost(s, a):
    if s == 0 or s == 4:
        return a
    elif s == 1 or s == 3:
        if a > 0:
            return a % 2
        else:
            return 2
    else:
        return (a + 1) % 2


for i in range(L):
    n = [min(DP[: i + 1]) for i in range(5)]
    a = A[i]
    DP[0] = n[0] + cost(0, a)
    DP[1] = n[1] + cost(1, a)
    DP[2] = n[2] + cost(2, a)
    DP[3] = n[3] + cost(3, a)
    DP[4] = n[4] + cost(4, a)
print((min(DP)))

-DP = [[0 for i in range(5)] for j in range(L + 1)] +DP = [0 for i in range(5)] +    n = [min(DP[: i + 1]) for i in range(5)] -    DP[i + 1][0] = min(DP[i][:1]) + cost(0, a) -    DP[i + 1][1] = min(DP[i][:2]) + cost(1, a) -    DP[i + 1][2] = min(DP[i][:3]) + cost(2, a) -    DP[i + 1][3] = min(DP[i][:4]) + cost(3, a) -    DP[i + 1][4] = min(DP[i][:5]) + cost(4, a) -print((min(DP[L]))) +    DP[0] = n[0] + cost(0, a) +    DP[1] = n[1] + cost(1, a) +    DP[2] = n[2] + cost(2, a) +    DP[3] = n[3] + cost(3, a) +    DP[4] = n[4] + cost(4, a) +print((min(DP)))