using System; using System.Text; using System.Linq; namespace ConsoleApp11 { class Program { static void Main(string[] args) { long N = long.Parse(Console.ReadLine()); long[] X = new long[N]; long[] Y = new long[N]; int tof = -1; for(long i = 0; i < N; i++) { var input = Console.ReadLine().Trim().Split(' '); X[i] = long.Parse(input[0]); Y[i] = long.Parse(input[1]); } for(long i = 0; i < N - 1; i++) { if(N > 1) { if ((Y[i] - X[i]) == Y[i + 1] - X[i + 1] && (Y[i] - X[i]) >= 0) { tof = 1; } else { tof = -1; break; } } else { if(Y[i] - X[i] >= 0) { tof = 1; } else { tof = -1; } } } if(tof == 1) { Console.WriteLine(Y[0] - X[0]); } else if(tof == -1) { Console.WriteLine(tof); } } } }