n, k, x, y = [int(i) for i in input().split()]
l = 0
l2 = 0
j = 0
j2 = 0
if max(n, k) == n:
    j = x
    j2 = y
else:
    j = y
    j2 = x
if (n + k) // j > min(n,k):
    l = (n+k) // j  - min(n,k)
if (n + k) // j2 > max(n,k):
    l2 = (n+k) // j2 - min(n,k)
print(n + k + l + l2)

