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