import java.util.*; import java.math.*; public class Main{ public static void main(String... args){ Scanner scan = new Scanner(System.in); int n = scan.nextInt(); System.out.println(Calc(n,scan)); } public static int Calc(int n,Scanner scan){ int result = -1; for(int i = 0; i < n; i++){ int x = scan.nextInt(); int y = scan.nextInt(); int fx = y-x; if(i == 0 && 0 < fx){ result = fx; }else if(result != fx){ result = -1; }else if(fx <= 0){ result = -1; } } return result; } }