import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int odd = 0; int even = 0; int max = 0; int[] a = new int[N]; int[] b = new int[N]; for(int i = 0; i < N; i++) { a[i] = sc.nextInt(); b[i] = sc.nextInt(); if(a[i] % 2 == 0) { even++; } else { odd++; } max = Math.max(max, a[i] + 4 * b[i]); } int ans = 0; if(even == 0 || odd == 0) { for(int i = 0; i < N; i++) { ans += ((max - a[i] - 4 * b[i]) / 2); } } else { ans = -1; } System.out.println(ans); } }