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