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

#2019-02-11



#DP



L = int(eval(input()))



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



def cost(a):

    if a:

        return [a, a%2, (a+1)%2, a%2, a]

    else:

        return [0, 2, 1, 2, 0]



def list_add(in1, in2):

    return [a + b for a, b in zip(in1, in2)]



for i in range(L):

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

    a = int(eval(input()))

    cos = cost(a)

    DP = list_add(n, cos)







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

#2019-02-11



#DP



L = int(eval(input()))



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



def cost(a):

    if a:

        return [a, a%2, (a+1)%2, a%2, a]

    else:

        return [0, 2, 1, 2, 0]



def list_add(in1, in2):

    return [a + b for a, b in zip(in1, in2)]



for i in range(L):

    a = int(eval(input()))

    cos = cost(a)

    DP[4] = min(DP[:5]) + cos[4]

    DP[3] = min(DP[:4]) + cos[3]

    DP[2] = min(DP[:3]) + cos[2]

    DP[1] = min(DP[:2]) + cos[1]

    DP[0] = min(DP[:1]) + cos[0]







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


def cost(a):
    if a:
        return [a, a % 2, (a + 1) % 2, a % 2, a]
    else:
        return [0, 2, 1, 2, 0]


def list_add(in1, in2):
    return [a + b for a, b in zip(in1, in2)]


for i in range(L):
    n = [min(DP[: i + 1]) for i in range(5)]
    a = int(eval(input()))
    cos = cost(a)
    DP = list_add(n, cos)
print((min(DP)))

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


def cost(a):
    if a:
        return [a, a % 2, (a + 1) % 2, a % 2, a]
    else:
        return [0, 2, 1, 2, 0]


def list_add(in1, in2):
    return [a + b for a, b in zip(in1, in2)]


for i in range(L):
    a = int(eval(input()))
    cos = cost(a)
    DP[4] = min(DP[:5]) + cos[4]
    DP[3] = min(DP[:4]) + cos[3]
    DP[2] = min(DP[:3]) + cos[2]
    DP[1] = min(DP[:2]) + cos[1]
    DP[0] = min(DP[:1]) + cos[0]
print((min(DP)))

-    n = [min(DP[: i + 1]) for i in range(5)] -    DP = list_add(n, cos) +    DP[4] = min(DP[:5]) + cos[4] +    DP[3] = min(DP[:4]) + cos[3] +    DP[2] = min(DP[:3]) + cos[2] +    DP[1] = min(DP[:2]) + cos[1] +    DP[0] = min(DP[:1]) + cos[0]