def solve(): N = int(input()) W = [0] * N for i in range(N): s, t = list(map(int, input().split())) W[i] = s + t * 4 mi = min(W) ans = 0 for i in range(N): n = W[i] - mi if n % 2 == 1: return -1 ans += n // 2 return ans def main(): print(solve()) if __name__ == '__main__': main()