n=int(input()) l=[] for i in range(n): a,b=map(int,input().split()) l.append(a+4*b) x,y=0,0 for c in l: if c%2==0: x+=1 else: y+=1 if (x==0 and y==n) or (x==n and y==0): ok=1 else: ok=0 if ok==0: print(-1) exit() m=max(l) ans=0 for x in l: ans+=abs(x-m)//2 print(ans)