using System; namespace yukicoder { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] strings1 = new int[N * 2]; //int[] strings2 = new int[str.Length]; for (int i = 0; i <= N * 2 - 1; i++) { var str = Console.ReadLine().Split(" "); int n = 0; strings1[i] = int.Parse(str[n]); strings1[i + 1] = int.Parse(str[n + 1]); i++; } for (int k = strings1.Length -1; k >= 0;) { if (strings1[k] - strings1[k - 1] == strings1[k - 2] - strings1[k - 3]) { k = k - 2; if(k == 1 && strings1[1] - strings1[0] > 0) { Console.WriteLine(strings1[1] - strings1[0]); break; } else if(k <= 1 && strings1[1] - strings1[0] <= 0 ) { Console.WriteLine("-1"); break; } continue; } else { Console.WriteLine("-1"); break; } } } } }