import math._ object Main { def main(args: Array[String]) { val sc = new java.util.Scanner(System.in) val n = sc.nextInt val xs = (1 to n) map { _ => val a, b = sc.nextInt a + 4 * b } val max = xs.max var ans = 0L for (x <- xs) { if ((max - x) % 2 == 1) { println(-1) return } ans += (max - x) / 2 } println(ans) } }