A, B, X, Y = map(int, input().split()) ans = 0 y = B/A*X if y <= Y: ans = max(ans, X+y) x = A/B*Y if x <= X: ans = max(ans, x+Y) print(ans)