import sys data=sys.stdin.readlines() data[1]=data[1].strip(" ") m=data[1].split(" ") if '\n' in m: m.remove('\n') def jox(l): val=l[0]%2 for item in l: if item%2!=val: return False return True for i in range(len(m)): m[i]=m[i].strip("\n") m[i]=int(m[i]) avg=int(sum(m)/len(m)) if float(int(sum(m)/len(m)))!=sum(m)/len(m) or jox(m)==False : print(-1) else: count=0 for item in m: if item>avg: count=count+int((item-avg)/2) print(count)