import math

cnt1, cnt2, x, y = [int(x)for x in raw_input().split(' ')]

ost1, ost2 = cnt1, cnt2
v, i = 0, 0

while ost1 > 0:
    #print 'Ost1 ', ost1
    if ost1 >= x:
        ost1 -= x - 1
        v += x
        i += 1
    else:
        v += ost1
        ost1 = 0
    #print v

#print i, v / x, i / y
ost2 -= i - i / y
if y - v % y - 1 > ost2:
    ost2 = 0
    v += ost2
else:
    ost2 -= y - v % y - 1
    #v += y - v % y - 1
    #print 'hui ', v

while ost2 > 0:
    #print 'Ost ', ost2
    if ost2 >= y:
        ost2 -= y - 1
        v += y
    else:
        v += ost2
        ost2 = 0
    #print v
print v
