import java.io.*; import java.util.*; import java.math.*; class Main185 { public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int ans = -1; boolean flg = false; for (int i = 0; i < n; i++) { if (flg) continue; String[] str = br.readLine().split(" "); int sub = Integer.parseInt(str[1]) - Integer.parseInt(str[0]); if (sub < 1) { flg = true; continue; } if (i == 0) { ans = sub; } else if (ans != sub) { flg = true; } } System.out.println(flg ? -1 : ans); } }