import java.util.ArrayList; import java.util.HashSet; import java.util.Scanner; import java.util.TreeSet; public class Main { static int N; static int[] X,Y; public static int solve(){ int answer = Y[0] - X[0]; if (answer < 0) return -1; for (int i = 1; i < N; i++) { if (Y[i] - X[i] != answer) return -1; else continue; } return answer; } public static void main(String[] args){ Scanner S = new Scanner(System.in); N = S.nextInt(); X = new int[N]; Y = new int[N]; for (int i = 0; i < N; i++) { X[i] = S.nextInt(); Y[i] = S.nextInt(); } System.out.println(solve()); } }