package me.yukicoder.lv1; import java.util.Scanner; public class No0185 { public static void main(String[] args) { try (Scanner sc = new Scanner(System.in)) { int N = sc.nextInt(); int ans = 0; int tmp = 0; for (int i = 0; i < N; i++) { int x = sc.nextInt(); int y = sc.nextInt(); ans = y - x; if (i == 0) { tmp = ans; } if (ans < 1 || tmp != ans) { ans = -1; break; } tmp = ans; } System.out.println(ans); } } }