package yukicoder; import java.util.Scanner; public class Yuki185 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int num = scan.nextInt(); int[][] num_arr = new int[num][2]; for(int i = 0; i < num ; i++) { for(int j = 0; j < 2; j++) { num_arr[i][j] = scan.nextInt(); } } scan.close(); int dif_numbers = 0; int parse_numbers = -1; for(int i = 0; i < num ; i++) { dif_numbers = num_arr[i][1] - num_arr[i][0]; if(dif_numbers < 0 ) { break; } else { if(i > 0 && parse_numbers != dif_numbers){ parse_numbers = -1; break; } parse_numbers = dif_numbers; } } System.out.println(parse_numbers); scan.close(); } }