
def ar():
    return map(int,raw_input().split())
cnt1,cnt2,x,y=ar()
if cnt1<cnt2:
    cnt1,cnt2,x,y=cnt2,cnt1,y,x

v1=cnt1
while True:

    rc1=v1/x
    #print rc1,v1
    if rc1+cnt1<=v1:
        break
    else:
        v1+=1
v2=v1
while True:

    rc2=v2/y
    rc3=v2/(x*y)
    #print rc2,rc3,cnt2,v2,"2"
    if rc2+rc3+cnt2<=v2:
        break
    else:
        v2+=1#(rc2+rc3)
print max(v1,v2)

##from fractions import gcd
##l,r=ar()#n=int(raw_input())
##flag=0
##for i in range(l,r+1):
##    if flag:
##        break
##    for j in range(i+1,r+1):
##        if flag:
##            break
##        for k in range(j+1,r+1):
##            if flag:
##                break
##            if gcd(i,j)==1 and gcd(j,k)==1 and gcd(i,k)!=1:
##                print i,j,k
##                flag=1
##                break
##if flag==0:
##    print "-1"
