using System; class Program { static void Main() { int N = int.Parse(Console.ReadLine()); int answer = int.MinValue; for (int i = 0; i < N; i++) { var parts = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int x = parts[1] - parts[0]; if (x <= 0) { Console.WriteLine(-1); return; } if (answer == int.MinValue) answer = x; else if (answer != x) { Console.WriteLine(-1); return; } } Console.WriteLine(answer); } }