using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { long ans = 0; int n = int.Parse(Console.ReadLine()); List lens = new List(); for (int i = 0; i < n; i++) { int[] ab = Console.ReadLine().Split().Select(int.Parse).ToArray(); lens.Add(ab[0] + ab[1] * 4); } int max = lens.Max(); foreach (int len in lens) { int dif = max - len; if (dif % 2 == 1) { ans = -1; break; } ans += dif / 2; } Console.WriteLine(ans); } }