package yukicoder; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class Main { public static void main(String[] args) { BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); try { int N = Integer.parseInt(read.readLine()); int i = 0, eo; List list = new ArrayList<>(N); String[] box = read.readLine().split(" "); long total = 0; total = Integer.parseInt(box[0]); total += Integer.parseInt(box[1]) * 4; list.add(total); if (total % 2 == 0) { eo = 0; } else { eo = 1; } long max = total; while (i++ < N - 1) { box = read.readLine().split(" "); total = Integer.parseInt(box[0]); total += Integer.parseInt(box[1]) * 4; list.add(total); if (total % 2 != eo) { break; } else { if (max < total) { max = total; } } } if (i < N) { System.out.println(-1); } else { Iterator it = list.iterator(); long ans = 0; while (it.hasNext()) { ans += max - it.next(); } System.out.println(ans / 2); } } catch (Exception e) { e.printStackTrace(); } } }