#coding:utf-8 def main(): N=input() n=[raw_input().split() for i in range(N)] s=[] for i in n: s.append(map(int,i)) t=set() for a,b in s: t.add(a+b*4) cnt=0 if len(t)==1: return 0 else: t=sorted(t,reverse=True) for i in t[1:]: if (t[0]-i)%2==0: cnt+=(t[0]-i)/2 else: return -1 return cnt if __name__=='__main__': print main()