import java.util.Scanner object Main extends App { val sc = new Scanner(System.in) val a, b, n, m = sc.nextLong val set1 = Seq(a, b).min val a1 = a - set1 val b1 = b - set1 val ans = set1 + Seq(a1 / n, b1 / m).max println(ans) }