w=gets.to_i.times.map{a,b=gets.split.map(&:to_i);a+4*b} r=w.first%2 ans=-1 if w.all?{|v|v%2==r} min=w.min ans=w.map{|v|v-min}.reduce(:+)/2 end p ans