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