cnt1, cnt2, x, y = map(int,raw_input().split())
m = cnt1 + cnt2
k = m/(x*y)
k1 = m - m/x
k2 = m - m/y
low = m+k
high = 10**18
ans = m+k
mid = m + k
while k1<cnt1 or k2<cnt2:
    mid = (low+high)>>1
    k = mid/(x*y)
    k1 = mid - mid/x
    k2 = mid - mid/y
    ans = mid + k
    if k1<cnt1 or k2<cnt2:
        low = mid+1
high = mid

while low<high:
    mid = (low+high)>>1
    k = mid/(x*y)
    k1 = mid - mid/x
    k2 = mid - mid/y
    ans = mid + k
    if k1<cnt1 or k2<cnt2:
        low = mid+1
    else:
        high = mid
mid = (low+high)>>1
k = mid/(x*y)
k1 = mid - mid/x
k2 = mid - mid/y
ans = mid + k
print ans    
    