import collections N = int(input()) A = list(map(int,input().split())) ZERO = A.count(0) ONE = A.count(1) L = [] SEP = [] for a in A: if a==2: if len(SEP)>0: L.append(SEP) SEP = [] else: SEP.append(a) L.append(SEP) #コストを設定 DP = collections.defaultdict(lambda:10**4) DP[(0,0)]=0 for l in L: NDP = collections.defaultdict(lambda:10**4) CA = collections.Counter(l) for k,v in DP.items(): z,o = k if z+len(l)<=ZERO: NDP[(z+len(l),o)]=min(NDP[(z+len(l),o)],v+CA[1]) if o+len(l)<=ONE: NDP[(z,o+len(l))]=min(NDP[(z,o+len(l))],v+CA[0]) DP = NDP if DP[(ZERO,ONE)]==10**4: print(-1) else: print(DP[(ZERO,ONE)]//2)