import java.util.Scanner; public class Test { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long n = sc.nextLong(), sum = 0, max = 0, t; boolean a = false, b = false; for(int i = 0; i < n; i++){ t = sc.nextLong() + sc.nextLong() * 4; if(t % 2 == 0){ a = true; } else { b = true; } max = Math.max(max, t); sum += t; } if(a && b){ System.out.println(-1); return; } System.out.println((max*n - sum)/2); } }