import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import static java.lang.System.in; public class Main { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(in)); int N = Integer.parseInt(reader.readLine()); String[] inputs; long max = Long.MIN_VALUE; long[] widths = new long[N]; for (int i = 0; i < N; i++) { inputs = reader.readLine().split(" "); long a = Long.parseLong(inputs[0]); long b = Long.parseLong(inputs[1]); widths[i] = a + 4 * b; max = Math.max(max, a + 4 * b); } long numOfSpaces = 0; boolean isPerfect = true; for (int i = 0; i < N; i++) { if ((max - widths[i]) % 2 != 0) { isPerfect = false; break; } else { numOfSpaces += (max - widths[i]) / 2; } } if (isPerfect) { System.out.println(numOfSpaces); } else { System.out.println(-1); } } }