using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace yukicoderTest { class Program { static void Main(string[] args) { string input = Console.ReadLine(); int N = int.Parse(input); int[] ans = new int[N]; for (int i = 0; i < N; i++) { string input2 = Console.ReadLine(); string[] lr = input2.Split(' '); int left = int.Parse(lr[0]); int right = int.Parse(lr[1]); ans[i] = (left - right) * -1; } int write = ans[0]; for (int i = 1; i < N; i++) { if (write < 0 || write != ans[i]) { write = -1; break; } } if (write < 0) { Console.WriteLine("-1"); } else { Console.WriteLine(write); } } } }