open System let solve a b c d = let isEnable a b c d = let j1 = a * c <= b let j2 = a + b <= d j1 && j2 [ for iA in 0 .. a do for iB in 0 .. b do if isEnable iA iB c d then yield iA ] |> Seq.max let a, b, c, d = let t = Console.ReadLine().Split() |> Array.map int t.[0], t.[1], t.[2], t.[3] solve a b c d |> Console.WriteLine