/**
 * Created by Phillip on 10/25/2014.
 */
import java.io.*;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(in.readLine());
        int cnt1 = Integer.parseInt(st.nextToken());
        int cnt2 = Integer.parseInt(st.nextToken());
        int x = Integer.parseInt(st.nextToken());
        int y = Integer.parseInt(st.nextToken());
        if(x<y){
            int co = x;
            x = y;
            y = co;
            co = cnt1;
            cnt1 = cnt2;
            cnt2 = co;
        }
        int index1=1;
        int index2=1000000000;
        //System.out.println("here");
        while(index1!=index2){
            //System.out.println(index1+" "+index2);
            int temp = (index1+index2)/2;
            int needed1 = 0;
            int needed2 = 0;
            if(temp/y-temp/(x*y)<=cnt1){
                needed1 = cnt1-temp/y+temp/(x*y);
            }
            if(temp/x-temp/(x*y)<=cnt2){
                needed2 = cnt2-temp/x+temp/(x*y);
            }
            if(needed1+needed2<=temp-temp/x-temp/y+temp/(x*y)){
                index2 = temp;
            }
            else{
                if(index1==temp) break;
                index1 = temp;
            }
        }
        System.out.println(index2);
        in.close();
        System.exit(0);
    }
}
