import java.util.*; public class Run { public static void main (String arg[]) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); int ans = 0; int tmpans = 0; int X, Y; for (int i = 0; i < N; i++) { X = scan.nextInt(); Y = scan.nextInt(); ans = Y - X; if (i == 0) tmpans = ans; if (ans < 0 || ans != tmpans) { ans = -1; break; } tmpans = ans; } System.out.println(ans); } }