public class No_185 { public static void main(String[] args) { java.util.Scanner sc = new java.util.Scanner(System.in); int n = sc.nextInt(); int x = sc.nextInt(); int y = sc.nextInt(); int ans = y - x; for (int i = 1; i < n; i++) { x = sc.nextInt(); y = sc.nextInt(); if (ans != y - x) { ans = -1; break; } } if (ans >= 0) { System.out.println(ans); } else { System.out.println(-1); } sc.close(); } }