using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace YukiCoder { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); var na = new int[N]; for (int i = 0; i < N; i++) { var va = Console.ReadLine().Split().Select(int.Parse).ToArray(); na[i] = va[0] + va[1] * 4; } int nMax = na.Max(); int nn = (nMax * N - na.Sum()) / 2; if(na.Any(c=> (nMax-c)%2==1)) Console.WriteLine(-1); else Console.WriteLine(nn); Console.ReadLine(); } } }