import java.util.*; class No0185{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); long n = sc.nextLong(); long result = 0; ArrayList x = new ArrayList(); for(int i = 0; i < n; i++){ x.add(sc.nextLong()); x.set(i, (sc.nextLong() - x.get(i))); } for(int i = 0; i < n; i++){ if(x.get(i) < 0){ result = -1; break; } if(x.get(i) != x.get(i + 1)){ result = -1; break; } if(i == n - 2){ break; } } if(result != -1) result = x.get(0); System.out.println(result); } }