import java.util.*; class No0185{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int result = 0; ArrayList x = new ArrayList(); ArrayList y = new ArrayList(); ArrayList z = new ArrayList(); for(int i = 0; i < n; i++){ x.add(sc.nextInt()); x.set(i, (sc.nextInt() - x.get(i))); } for(int i = 0; i < n; i++){ if(x.get(i) < 0 || x.get(i - 1) < 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); } }