import java.util.Scanner; public class No185 { public static void main(String[] args) { Scanner s = new Scanner(System.in); int count = s.nextInt(); int diff = -1; for (int i = 0; i < count; i++) { if (i == 0) { diff = -s.nextInt() + s.nextInt(); if (diff < 1) { diff = -1; } } else if (-s.nextInt() + s.nextInt() != diff) { diff = -1; break; } } System.out.println(diff); } }