import sys input=lambda: sys.stdin.readline().rstrip() n=int(input()) A=[] for _ in range(n): a,b=map(int,input().split()) A.append(a+4*b) A.sort() a=A[-1] chk=True for i in range(n-1): if (a-A[i])%2: chk=False break if not chk: print(-1) else: print((a-A[0])//2)