import sys def avg_cut(l): b = False for k in l: if abs(sum(l)/len(l) -k)%2 ==0: b = True else: b = False break return b m = 0 n = int(input()) l= input().split() l2 = [int(x) for x in l] bb= avg_cut(l2) if len(l2) ==1: print(0) elif sum(l2) % len(l2) == 0 and bb : while len(set(l2)) != 1: l2[l2.index(max(l2))] = max(l2) - 2 l2[l2.index(min(l2))] = min(l2) + 2 m += 1 print(m) else: print(-1)