n = int(input()) ls = [] for i in range(n): a,b = map(int, input().split()) sm = a+4*b ls.append(sm) oe = [] for i in ls: if i%2 == 0: oe.append(0) else: oe.append(1) if len(set(oe)) == 2: print('-1') else: total = 0 mx = max(ls) for i in ls: total += mx - i print(int(total/2))