par = map(int, raw_input().split(" "))
a, b, x, y = par[0], par[1], par[2], par[3]

def gcd(a, b):
    if b == 0:
        return a
    a,b = b, a%b
    return gcd(a,b)

if a < b:
    a, b = b, a
    x, y = y, x

'''
sol = 1
while a > 0 or b > 0:
    if sol % x == 0:
        if sol % y != 0:
            #print sol, "y"
            b -= 1
    else:
        #print sol, "x"
        a -= 1
    sol += 1
print sol-1
'''

m = (a+1)//x
ax = m*x + a- m*(x-1)
by = 0

for i in range(1, m+1):
    if i*x % y != 0:
        by += 1
left = b - by

#print ax, left 

if left == 0:
    print ax
else:
    now = 1
    while now <= ax and left > 0:
        if now % y != 0:
            left -= 1
            ax += 1
            while ax % a == 0:
                ax += 1

            #print "b", now, left
            #print "a", ax 
        now += 1
    print ax
    
        
