N = int(input()) a, b = map(int, input().split()) S = [a + b * 4] gf = a % 2 for _ in range(N - 1): x, y = map(int, input().split()) S.append(x + y * 4) if x % 2 != gf: print(-1) break else: print((max(S) * N - sum(S)) // 2)