N = gets.to_i X = N.times.map { gets.split.map(&:to_i) }.map { |a, b| a + 4 * b } if X.all?(&:odd?) || X.all?(&:even?) puts X.map { |x| (X.max - x) / 2 }.sum else puts(-1) end