n = int(input()) width = [0] * n even = False odd = False for i in range(n): a, b = [int(x) for x in input().split()] width[i] = a + 4 * b if a % 2 == 0: even = True else: odd = True res = 0 if even and odd: res = -1 else: len_max = max(width) for w in width: res += len_max - w res //= 2 print(res)