n = int(input()) w = [list(map(int, input().split())) for _ in range(n)] q = list() for x in w: q.append(x[0] + x[1]*4) m = max(q) if all([a % 2 == 0 for a in q]) or all([a % 2 != 0 for a in q]): print(sum([m - i for i in q])//2) else: print(-1)