package m.shin; import java.util.Scanner; public class Con185 { public static void main(String[] args) { Scanner s = new Scanner(System.in); int N = s.nextInt() , d = 0; int[] X = new int[N]; int[] Y = new int[N]; for(int i = 0;i < N;i++){ X[i] = s.nextInt(); Y[i] = s.nextInt(); if(i >= 1){ if(d != Y[i] - X[i] || Y[i] - X[i] <= 0){ d = -1; } }else{ if(Y[i] - X[i] <= 0){ d = -1; }else{ d = Y[i] - X[i]; } } } s.close(); System.out.println(d); } }