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; long max = 0; long[] a = new long[N]; long[] b = new long[N]; for(int i = 0; i < N; i++) { a[i] = sc.nextLong(); b[i] = sc.nextLong(); if(a[i] % 2 == 0) { even++; } else { odd++; } max = Math.max(max, a[i] + 4 * b[i]); } long 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); } }