def oi(): return int(input())
def os(): return input()
def mi(): return list(map(int, input().split()))

# import sys
# input = sys.stdin.readline
# import sys
# sys.setrecursionlimit(10**8)
# import pypyjit
# pypyjit.set_param('max_unroll_recursion=-1')
input_count = 0

from collections import Counter
N = oi()
A = mi()
elements = []
temp = {0:0, 1:0}
for a in A:
    if a == 2:
        if len(temp)!=0:
            elements.append(temp)
        temp = {0:0, 1:0}
    else:
        temp[a] += 1            
if len(temp)!=0:
    elements.append(temp)
zero_num = 0
one_num = 0
diffs = []
for e in elements:
    if e[0] > e[1]:
        one_num += e[1]
        diffs.append([e[0] + e[1], e[0] - e[1], 0]) #  全体の0と1の, 増える交換回数, 同じかフラグ
    elif e[0] < e[1]:
        zero_num += e[0]
        diffs.append([-1*(e[0] + e[1]), e[1] - e[0], 0])
    else:
        one_num += e[1]
        diffs.append([e[0] + e[1], 0, 1])
if zero_num ==  one_num:
    print(zero_num)
else:
    # 一致してなければDP
    INF = 10**5
    dp = [[INF] * (N*2 +2) for _ in range(len(elements)+1)]

    dp[0][N+1] = 0
    for y,d in enumerate(diffs):
        for x in range(0, 2*N+2):
            if dp[y][x] != INF:
                if 0 <= x+d[0] <= 2*N+1:
                    dp[y+1][x+d[0]] = min(dp[y+1][x+d[0]], dp[y][x]+d[1])
                if d[2] == 1:
                    if 0 <= x-d[0] <= 2*N+1:
                        dp[y+1][x-d[0]] = min(dp[y+1][x-d[0]], dp[y][x]+d[1])

    ret = dp[-1][zero_num-one_num + N+1]
    if ret != INF:
        print(ret)
    else:
        print(-1)