import sys

nums = sys.stdin.readline().split(" ")
cnt1 = int(nums[0])
cnt2 = int(nums[1])
x = int(nums[2])
y = int(nums[3])

num1 = x - 1
num2 = y - 1

total1 = (cnt1//num1)*x
total2 = (cnt2//num2)*y

if cnt1 % num1 == 0:
	total1 -= 1
if cnt2 % num2 == 0:
	total2 -= 1
count1 = (cnt1//num1)*num1
count2 = (cnt2//num2)*num2

total1 = total1 + cnt1 - count1
total2 = total2 + cnt2 - count2

print(max(total1, total2))