a,b,x,y=map(int,input().split());
l=a+b;
r=(a+b)*5;
res=0;
def judge(m,a,b,x,y):
    return (m-m//x>=a and m-m//y>=b and m-m//(x+y)>=a+b);
while l<=r:
    m=(l+r)//2;
    if judge(m,a,b,x,y):
        r=m-1;
        res=m;
    else :l=m+1;
print(res);