#美しいWhiteSpace(1) N = int(input()) s = [] for i in range(N): a = list(map(int , input().split())) s.append(a[0] + a[1] * 4) s.sort() max = s[-1] c = 0 for i in s: if (max - i) % 2 == 0: c += (max - i) / 2 else: c = -1 break print(int(c))