n = int(input()) a = [] b = [] for i in range(n): ai,bi=[int(i) for i in input().split()] a.append(ai) b.append(bi) def max(a, b): if a >= b: return a else: return b res = 0 target = a[0] + 4*b[0] for i in range(n): if i == 0: continue cur = a[i] + 4*b[i] if (target - cur) % 2 == 0: target = max(target, cur) else: res = -1 break if res == -1: print(res) else: for i in range(n): res += target - (a[i] + 4*b[i]) print(int(res/2))