#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 = [[float("inf") for i in range(5)] for j in range(L+1)]

for i in range(5):

    DP[0][i] = 0



def cost(s, i, A):

    if s == 0 or s == 4:

        return A[i]

    elif s == 1 or s == 3:

        if A[i] > 0:

            if A[i]%2 == 0:

                return 0

            else:

                return 1

        else:

            return 2

    else:

        if A[i]%2 == 1:

            return 0

        else:

            return 1



for i in range(L):

    DP[i+1][0] = DP[i][0] + cost(0, i, A)

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

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

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

    DP[i+1][4] = min(DP[i][:5]) + cost(4, i, 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)] for j in range(L+1)]



def cost(s, i, A):

    if s == 0 or s == 4:

        return A[i]

    elif s == 1 or s == 3:

        if A[i] > 0:

            if A[i]%2 == 0:

                return 0

            else:

                return 1

        else:

            return 2

    else:

        if A[i]%2 == 1:

            return 0

        else:

            return 1



for i in range(L):

    DP[i+1][0] = DP[i][0] + cost(0, i, A)

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

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

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

    DP[i+1][4] = min(DP[i][:5]) + cost(4, i, 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 = [[float("inf") for i in range(5)] for j in range(L + 1)]
for i in range(5):
    DP[0][i] = 0


def cost(s, i, A):
    if s == 0 or s == 4:
        return A[i]
    elif s == 1 or s == 3:
        if A[i] > 0:
            if A[i] % 2 == 0:
                return 0
            else:
                return 1
        else:
            return 2
    else:
        if A[i] % 2 == 1:
            return 0
        else:
            return 1


for i in range(L):
    DP[i + 1][0] = DP[i][0] + cost(0, i, A)
    DP[i + 1][1] = min(DP[i][:2]) + cost(1, i, A)
    DP[i + 1][2] = min(DP[i][:3]) + cost(2, i, A)
    DP[i + 1][3] = min(DP[i][:4]) + cost(3, i, A)
    DP[i + 1][4] = min(DP[i][:5]) + cost(4, i, 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)] for j in range(L + 1)]


def cost(s, i, A):
    if s == 0 or s == 4:
        return A[i]
    elif s == 1 or s == 3:
        if A[i] > 0:
            if A[i] % 2 == 0:
                return 0
            else:
                return 1
        else:
            return 2
    else:
        if A[i] % 2 == 1:
            return 0
        else:
            return 1


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

-DP = [[float("inf") for i in range(5)] for j in range(L + 1)] -for i in range(5): -    DP[0][i] = 0 +DP = [[0 for i in range(5)] for j in range(L + 1)]