import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(readline()) m = map(int,read().split()) W = [x+4*y for x,y in zip(m,m)] max_w = max(W) if any((max_w-x)&1 for x in W): print(-1) else: answer = sum(max_w-x for x in W) // 2 print(answer)