N=int(input()) s=[0]*N ans=0 for i in range(N): a,b=map(int,input().split()) s[i]=a+4*b for k in s: ans+=max(s)-k print (ans//2 if ans%2==0 else -1)