import java.util.Scanner; public class No185 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int[] input = new int[N*2]; for (int i=0; i< N * 2; i++) input[i] = sc.nextInt(); int dif = input[1] - input[0]; int count = 0; if(dif <= 0) System.out.println("-1"); else{ for(int i=0; i < N * 2; i = i + 2){ if(input[i] + dif == input[i+1]) count++; } if(count ==N ) System.out.println(dif); else System.out.println("-1"); sc.close(); } } }