import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = Integer.parseInt(sc.next()); Map map = new HashMap<>(); for (int i = 0; i < N; i++) { long X = Long.parseLong(sc.next()); long Y = Long.parseLong(sc.next()); if (Y - X > 0) { if (!map.containsKey(Y-X)) map.put(Y-X, (long) 0); map.put(Y-X, map.get(Y-X)+1); } } if (map.size() == 1) { map.forEach((aLong, aLong2) -> System.out.println(aLong)); } else { System.out.println("-1"); } } }