import java.util.*; public class Exercise96{ public static void main (String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[][] x = new int[n][2]; for(int i = 0; i < n; i++){ x[i][0] = sc.nextInt(); x[i][1] = sc.nextInt(); } int a = x[0][1] - x[0][0]; if(a < 1){ System.out.println(-1); return; } for(int i = 1; i < n; i++){ if(x[i][1] - x[i][0] != a){ System.out.println(-1); return; } } System.out.println(a); } }