import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); int []l = new int[N]; for(int i = 0; i < N; i++) { int a = scan.nextInt(); int b = scan.nextInt(); l[i] = a + 4 * b; } scan.close(); Arrays.sort(l); int max = l[N - 1]; int c = 0; for(int i = 0; i < N - 1; i++) { if((max - l[i]) % 2 == 1) { System.out.println(-1); System.exit(0); }else { c += (max - l[i]) / 2; } } System.out.println(c); } }