using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { Console.ReadLine(); var list = new List(); var line = ""; while (string.IsNullOrEmpty(line = Console.ReadLine()) == false) { list.Add(line); } var XY = list.Select(l => { var xy = l.Split(' '); return new { X = int.Parse(xy[0]), Y = int.Parse(xy[1]) }; }); // □ + X = Y かつ、□は正整数 // □が存在しない場合は -1 を出力 // □が存在する場合は、□の数値を出力 var S = XY.Select(xy => xy.Y - xy.X); if( S.Where(s => s <= 0).Count() > 0 ) { Console.WriteLine("-1"); return; } if( S.Distinct().Count() != 1 ) { Console.WriteLine("-1"); return; } Console.WriteLine(S.First()); } }