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: if i % 2 == 0: c += (M-i)//2 else: c = -1 print(c)