n = int(input()) list = [] for i in range(n): a, b = map(int, input().split()) list.append(a + b * 4) max = max(list) counter = 0 for e in sorted(list): if (max - e) % 2 == 0: counter += max - e else: print(-1) break else: print(int(counter / 2))