__author__ = 'Moustapha Saad'
cnt1, cnt2, x, y = map(int, raw_input().split())

acc = 0
while cnt1 > 0 or cnt2 > 0:
    acc += 1
    if cnt1 > 0 and acc%x != 0:
        cnt1 -= 1
    if cnt2 > 0 and acc%y != 0:
        cnt2 -= 1
print acc
