import java.util.Scanner; public class Main_yukicoder185 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int prev = 0; boolean flag = true; for (int i = 0; i < n; i++) { int x = sc.nextInt(); int y = sc.nextInt(); if (i > 0) { if (y - x != prev) { flag = false; break; } } else { prev = y - x; } } if (flag && prev > 0) { System.out.println(prev); } else { System.out.println("-1"); } sc.close(); } }