import math

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

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

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

##print i, v1 / x, i / y
ost2 -= i - i / y

#print v1, ost2, i / y

if y - v1 % y - 1 > ost2 and ost2 > 0:
    v1 += ost2
    ost2 = 0
elif ost2 > 0:
    ost2 -= y - v1 % y - 1
    v1 += y - v1 % y
    #print 'hui ', v1

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

#print 'lol' , v1

# ===============================================

ost2, ost1 = cnt1, cnt2
x, y = y, x
v2, i = 0, 0

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

##print i, v2 / x, i / y
ost2 -= i - i / y
if y - v2 % y - 1 > ost2 and ost2 > 0:
    v2 += ost2
    ost2 = 0
elif ost2 > 0:
    ost2 -= y - v2 % y - 1
    v2 += y - v2 % y
    #print 'hui ', v2

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

#print v1, v2
print min(v1, v2)
