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