using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace yukicoder_185 { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[,]s = new int[n, 2]; int check = 0; for (int i = 0; i < n; i++) { string[] t = Console.ReadLine().Split(' '); s[i, 0] = int.Parse(t[0]); s[i, 1] = int.Parse(t[1]); if (s[i, 1] - s[i, 0] < 0) { check++; } } if (check != 0) { Console.WriteLine(-1); } else { if (n == 1) { Console.WriteLine(s[0, 1] - s[0, 0]); }else { for (int i = 1; i < n; i++) { if (s[i, 1] - s[i, 0] != s[i - 1, 1] - s[i - 1, 0]) { check++; break; } } if (check != 0) { Console.WriteLine(-1); } else { Console.WriteLine(s[0, 1] - s[0, 0]); } } } Console.ReadLine(); } } }