import java.io.*;
import java.util.*;
public class CF_483B {
    public static void main(String[] args) throws IOException {
        new CF_483B().solve();
    }
    
    long countMultLess(long k, long upperBorder){
        return upperBorder/k;       
    }
    boolean isEnough(long v, long cnt1, long cnt2, long x, long y){
        long badBoth=countMultLess(x*y, v);
        long bad1=countMultLess(x, v);
        long bad2=countMultLess(y, v);
        long goodBoth=v-bad1-bad2+badBoth;
        long min=Math.min(bad2, cnt1);
        //bad2-=min;
        cnt1-=min;
        min=Math.min(bad1, cnt2);
        //bad2-=min;
        cnt2-=min;
        return (cnt1+cnt2<=goodBoth);
    }
    
    void solve() throws IOException{
        
        InputStream in = System.in;
        PrintStream out = System.out;
        
//        in = new FileInputStream("in.txt");
//        out = new PrintStream("out.txt");
        
        Scanner sc=new Scanner(in);        
        int cnt1=sc.nextInt(), cnt2=sc.nextInt(), x=sc.nextInt(), y=sc.nextInt();
        long bad=0, good=1000_000_000_000L;
        while (good-bad>1){
            long m=bad+(good-bad)/2;
            if (isEnough(m, cnt1, cnt2, x, y))
                good=m;
            else 
                bad=m;
        }
        out.println(good);
    }
}


