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