package yukicoder; import java.io.BufferedReader; import java.io.InputStreamReader; 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 num; String[] box = read.readLine().split(" "); int x, y; x = Integer.parseInt(box[0]); y = Integer.parseInt(box[1]); num = y - x; if (num < 0) { System.out.println(-1); return; } int i; for (i = 1; i < N; ++i) { box = read.readLine().split(" "); x = Integer.parseInt(box[0]); y = Integer.parseInt(box[1]); if (num != (y - x)) { break; } } if (i < N) { System.out.println(-1); } else { System.out.println(num); } } catch (Exception e) { e.printStackTrace(); } } }