def R(): return map(int, input().split())
def I(): return int(input())
def S(): return str(input())

def L(): return list(R())

from collections import Counter 

import math
import sys

from itertools import permutations


import bisect

#print(bisect.bisect_right([1,2,3],2))
#print(bisect.bisect_left([1,2,3],2))

cnt1,cnt2,x,y=R()

l=1
r=10**18

while r>l+1:
    m=(l+r)//2
    t1=max(cnt1-m//y,0)
    t2=m-m//(x*y)-m//x-m//y-t1

    if m-m//(x*y)>=cnt1+cnt2 and t2>=0:

        r=m
    else:
        l=m

print(r)


