'''
Created on Oct 24, 2014

@author: Ismael
'''    

def func(n,a):
    return n-n//a

def binary_search(iMin, iMax, a, t):
    while True:
        if iMax < iMin:
            return iMax-1
        m = (iMin + iMax) // 2
        y = func(m,a)
        if y < t:
            iMin = m + 1
        elif t < y:
            iMax = m - 1
        else:
            return m

VMIN=1
VMAX=2*10**9
cnt1,cnt2,x,y = map(int,input().split())
a = min(x,y)
b = max(x,y)
'''n1 = cnt1*a)
n1 = binary_search(VMIN,VMAX,a,b,cnt1)
print(n1,n2)'''
n1 = binary_search(VMIN,VMAX,a,cnt1)
n2 = binary_search(VMIN,VMAX,b,cnt2)
print(max(n1,n2))