
def ar():
    return map(int,raw_input().split())
##n,k=ar()
##n1=n
##j=1
##di={}
##t=[]
##f=True
##for i in range(k,0,-1):
##    t.append(j)
##    di[j]=True
##    if f:
##        j+=i
##    else:
##        j-=i
##    f = not f
##    n1-=1
##for i in t:
##    print i,
##for j in range(1,n+1):
##    if not di.get(j,False):
##        print j,

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
def tr(i,c,r):
    j=c
    while True:
       rj=j/r
a=cnt1
while True:
    ra=a/x
    if ra+cnt1==a:
        break
    else:
        a+=1
b=cnt2
while True:
    rb=b/x
    if rb+cnt2==b:
        break
    else:
        b+=1
c=min(a,b)/(x*y)
v2=max(cnt1,cnt2)
while True:
    rc1=v2/(x*y)
    rc2=v2/y
    rc3=v2/(x)
    #print rc2,rc3,cnt2,v2,"2"
    if (v2-rc3-c>=cnt1 and v2-rc2>=cnt2) or (v2-rc3>=cnt1 and v2-rc2-c>=cnt2):
        break
    else:
        v2+=1#(rc2+rc3)
print 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"
