a=(1..gets.to_i).map{a,b=gets.split.map &:to_i;a+4*b} s=0 p a.map{|e|break if (s+=a.max-e)%2>0}?s/2:-1