using System; namespace yukicoder { class Program { static void Main(string[] args) { int a = int.Parse(Console.ReadLine()); int count = 0; int ans = 0; for (int i = 0; i < a; i++) { string[] s = Console.ReadLine().Split(' '); int b = int.Parse(s[0]); int c = int.Parse(s[1]); if (i == 0) { for (int j = 1; j < 1000000; j++) { if (c == b + j) { count++; ans = j; } } } else { if (c == b + ans) { count++; } } } if (count == a) { Console.WriteLine(ans); } else { Console.WriteLine("-1"); } } } }