using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var list = new List(); int[] input; var result = 0; for (int i = 0; i < N; i++) { input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); result = input[1] - input[0]; if (result >= 0) list.Add(result); } if (list.Count() == 0) Console.WriteLine(-1); else Console.WriteLine((list.Distinct().Count() == 1) ? list[0] : -1); } }