import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class No00000185_Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); String[] strArr = br.readLine().split(" "); int x = Integer.parseInt(strArr[0]); int y = Integer.parseInt(strArr[1]); int ans = y - x; if(ans <= 0) { System.out.println(-1); return; } n--; boolean flg = true; while(n > 0) { strArr = br.readLine().split(" "); x = Integer.parseInt(strArr[0]); y = Integer.parseInt(strArr[1]); if(ans != y - x) { flg = false; break; } n--; } System.out.println(flg ? ans : -1); } }