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; for (int i = 0; i < N; i++) { if (i == 0) { int x = sc.nextInt(); int y = sc.nextInt(); if (y - x < 1) { ans = -1; } } else { int x = sc.nextInt(); int y = sc.nextInt(); if (y - x != ans) { ans = -1; break; } } } System.out.println(ans); } } }