import numpy as np N = int(input()) A = tuple(map(int, input().split())) INF = 10000 c, h = 0, 0 # 肉食, 草食 dp = np.full(N, INF) dp[0] = 0 for i in range(N + 1): if i == N or A[i] == 2: if c == h == 0: continue new_dp = dp + c # 草食に揃える new_dp[c + h:] = np.minimum(new_dp[c + h:], dp[:-c - h] + h) # 肉食に揃える dp = new_dp c, h = 0, 0 elif A[i] == 0: c += 1 elif A[i] == 1: h += 1 res = dp[A.count(0)] if res >= INF: print(-1) else: print(res // 2)