l = int(eval(input()))

a = []

for i in range(l):

  a.append(int(eval(input())))

  

dp=[[0]*5 for i in range(l+1)]



for i in range(0,l):

  if a[i]==0:

    even=2

  else:

    even=a[i]%2

  

  dp[i+1][0]=dp[i][0]+a[i]

  dp[i+1][1]=min(dp[i][0],dp[i][1]) + even

  dp[i+1][2]=min(dp[i][0],dp[i][1],dp[i][2]) + (a[i]+1)%2

  dp[i+1][3]=min(dp[i][0],dp[i][1],dp[i][2],dp[i][3]) + even

  dp[i+1][4]=min(dp[i][0],dp[i][1],dp[i][2],dp[i][3],dp[i][4]) + a[i]

  

print((min(dp[l])))

  
n  = int(eval(input()))

a = [int(eval(input())) for i in range(n)]



# 0区間、偶数区間(2以上)、奇数区間、偶数区間(2以上)、0区間

dp = [[0] * (5) for i in range(n + 1)]

for i in range(n):

    dp[i + 1][0] = dp[i][0] + a[i]



    dp[i + 1][1] = min(dp[i][0:2]) + (a[i] % 2)

    if a[i] == 0:

        dp[i + 1][1] += 2

        

    dp[i + 1][2] = min(dp[i][0:3]) + (a[i] + 1) % 2

    

    dp[i + 1][3] = min(dp[i][0:4]) + (a[i] % 2)

    if a[i] == 0:

        dp[i + 1][3] += 2

        

    dp[i + 1][4] = min(dp[i][0:5]) + a[i]



print((min(dp[-1])))
l = int(eval(input()))
a = []
for i in range(l):
    a.append(int(eval(input())))
dp = [[0] * 5 for i in range(l + 1)]
for i in range(0, l):
    if a[i] == 0:
        even = 2
    else:
        even = a[i] % 2
    dp[i + 1][0] = dp[i][0] + a[i]
    dp[i + 1][1] = min(dp[i][0], dp[i][1]) + even
    dp[i + 1][2] = min(dp[i][0], dp[i][1], dp[i][2]) + (a[i] + 1) % 2
    dp[i + 1][3] = min(dp[i][0], dp[i][1], dp[i][2], dp[i][3]) + even
    dp[i + 1][4] = min(dp[i][0], dp[i][1], dp[i][2], dp[i][3], dp[i][4]) + a[i]
print((min(dp[l])))

n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
# 0区間、偶数区間(2以上)、奇数区間、偶数区間(2以上)、0区間
dp = [[0] * (5) for i in range(n + 1)]
for i in range(n):
    dp[i + 1][0] = dp[i][0] + a[i]
    dp[i + 1][1] = min(dp[i][0:2]) + (a[i] % 2)
    if a[i] == 0:
        dp[i + 1][1] += 2
    dp[i + 1][2] = min(dp[i][0:3]) + (a[i] + 1) % 2
    dp[i + 1][3] = min(dp[i][0:4]) + (a[i] % 2)
    if a[i] == 0:
        dp[i + 1][3] += 2
    dp[i + 1][4] = min(dp[i][0:5]) + a[i]
print((min(dp[-1])))

-l = int(eval(input())) -a = [] -for i in range(l): -    a.append(int(eval(input()))) -dp = [[0] * 5 for i in range(l + 1)] -for i in range(0, l): +n = int(eval(input())) +a = [int(eval(input())) for i in range(n)] +# 0区間、偶数区間(2以上)、奇数区間、偶数区間(2以上)、0区間 +dp = [[0] * (5) for i in range(n + 1)] +for i in range(n): +    dp[i + 1][0] = dp[i][0] + a[i] +    dp[i + 1][1] = min(dp[i][0:2]) + (a[i] % 2) -        even = 2 -    else: -        even = a[i] % 2 -    dp[i + 1][0] = dp[i][0] + a[i] -    dp[i + 1][1] = min(dp[i][0], dp[i][1]) + even -    dp[i + 1][2] = min(dp[i][0], dp[i][1], dp[i][2]) + (a[i] + 1) % 2 -    dp[i + 1][3] = min(dp[i][0], dp[i][1], dp[i][2], dp[i][3]) + even -    dp[i + 1][4] = min(dp[i][0], dp[i][1], dp[i][2], dp[i][3], dp[i][4]) + a[i] -print((min(dp[l]))) +        dp[i + 1][1] += 2 +    dp[i + 1][2] = min(dp[i][0:3]) + (a[i] + 1) % 2 +    dp[i + 1][3] = min(dp[i][0:4]) + (a[i] % 2) +    if a[i] == 0: +        dp[i + 1][3] += 2 +    dp[i + 1][4] = min(dp[i][0:5]) + a[i] +print((min(dp[-1])))