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