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 (ans == c - b&&c-b!=0) { count++; } if (i == 0) { ans = c - b; if (ans>=1) { count++; } } } if (count == a) { Console.WriteLine(ans); } else { Console.WriteLine("-1"); } } } }