A,B,C,D = gets.split.map(&:to_i) (0..A).map{|x| [x, x * C]}.map{|x| x << x.sum}.filter{|ab| ab[2] <= D && ab[1] <= B}.max_by{|x| x[0]}[0]