L=[] for i in range(int(input())): A,B=map(int,input().split()) L+=[A+4*B] M=max(L) O=0 for C in L: D=M-C if D%2: O=-1 break else:O+=D//2 print(O)