import java.util.*; public class Run { public static void main (String arg[]) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); int [] a = new int[N]; int [] b = new int[N]; int [] c = new int[N]; int ans = 0; int max = 0; int num = -1; boolean x = false, y = false; for (int i = 0; i < N; i++) { a[i] = scan.nextInt(); b[i] = scan.nextInt(); if (a[i]%2==0) x = true; else y = true; if (x && y) break; c[i] = a[i] + 4*b[i]; if (max < c[i]) { num = i; max = c[i]; } } for (int i = 0; i < N; i++) { if (x && y) { ans = -1; break; } ans += (c[num] - c[i])/2; } System.out.println(ans); } }