import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String[] r=br.readLine().split(" ");
        long n=Long.parseLong(r[0]);
        long m=Long.parseLong(r[1]);
        long x=Long.parseLong(r[2]);
        long y=Long.parseLong(r[3]);
        System.out.println(binarySearch(n+m,2*(n+m),n,m,x,y,x*y));
    }

    static long binarySearch(long i, long j, long n, long m, long x,
            long y, long p) {
        if (i==j){
            return i;
        }
        else{
            long med=(i+j)/2;
            long divx=med/y;
            long divy=med/x;
            long divp=med/p;
            divx-=divp;
            divy-=divp;
            long auxn=n-divx;
            long auxm=m-divy;
            if (auxn<0){
                auxn=0;
            }
            if (auxm<0){
                auxm=0;
            }
            long disponibles=med-divx-divy+divp;
            if (disponibles>=auxn+auxm){
                return binarySearch(i,med,n,m,x,y,p);
            }
            else{
                return binarySearch(med+1,j,n,m,x,y,p);
            }
        }
        
    }

}
