import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = Integer.parseInt(sc.next()); long X = Long.parseLong(sc.next()); long Y = Long.parseLong(sc.next()); long num = 0; boolean flag = false; if (Y - X > 0) { num = Y - X; for (int i = 0; i < N - 1; i++) { X = Long.parseLong(sc.next()); Y = Long.parseLong(sc.next()); if (Y - X > 0) { if (!(num == Y - X)) { flag = true; System.out.println("-1"); break; } } else { flag = true; System.out.println("-1"); break; } if (!flag) { System.out.println(num); } } } else { System.out.println("-1"); } } }