import java.util.*; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int ans = -1; for(int i = 0; i < n; i++) { int a = sc.nextInt(); int b = sc.nextInt(); int c = b - a; if(i == 0 && c > 0) { ans = c; } else if(ans != c) { ans = -1; } else if(c <= 0) { ans = -1; } } System.out.println(ans); } }