N=int(input()) S=[int(x)+int(y)*4 for x,y in [input().split()for _ in'1'*N]] m=max(S) A=[m-x for x in S] B=set([a%2 for a in A]) print((sum(A)//2,-1)[len(B)>1])