import java.util.Arrays; import java.util.LinkedList; import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); long[] array = new long[N]; for(int i = 0; i < N; i++){ final int a = sc.nextInt(); final int b = sc.nextInt(); array[i] = a + 4 * b; } boolean ok = true; final long fst_mod = array[0] % 2; for(int i = 1; i < N; i++){ if(array[i] % 2 != fst_mod){ ok = false; break; } } if(!ok){ System.out.println(-1); }else{ long max = 0; for(int i = 0; i < N; i++){ max = Math.max(max, array[i]); } long count = 0; for(int i = 0; i < N; i++){ count += (max - array[i]) / 2; } System.out.println(count); } } }