#coding: UTF-8 import sys import re import itertools from math import log from collections import deque ### defs ### ### main ### N = int(sys.stdin.readline()) AB = [] for _ in range(N): a,b=map(int,sys.stdin.readline().split()) AB.append((a,b)) if (len(list(filter(lambda x:(x[0]+4*x[1])%2==0,AB))) != 0 and len(list(filter(lambda x:(x[0]+4*x[1])%2==1,AB))) != 0): print(-1) else: mx = max(map(lambda x:x[0]+4*x[1], AB)) ans = sum(map(lambda x:(mx - x[0]-4*x[1])//2, AB)) print(ans)