import java.util.Scanner; public class Main { public static void main(String []args){ Scanner in = new Scanner(System.in); int loops = in.nextInt(); int x = in.nextInt(), y = in.nextInt(); int ans = y - x; if(ans < 0){ System.out.println(-1); return; } while(in.hasNextInt()){ x = in.nextInt(); y = in.nextInt(); if(ans != (y - x)){ System.out.println(-1); return; } } System.out.println(ans); } }