n = int(input()) l = [] for _ in range(n): a, b = map(int, input().split()) l.append(a + 4*b) y = max(l) z = 0 for i in l: if (y-i) % 2 == 0: z += (y-i) // 2 else: z = -1 break print(z)