
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.PrintWriter;
import java.io.OutputStreamWriter;

public class Solution {
	
	public static void main(String args[])throws IOException{
		Reader.init(System.in);
		PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));
		
		int cnt1 = Reader.nextInt();
		int cnt2 = Reader.nextInt();
		
		int x = Reader.nextInt();
		int y = Reader.nextInt();
		
		int i = 1;
		int sum1 = 0;
		int sum2 = 0;
		
		while(sum1 < cnt1 || sum2 < cnt2){
			if(i%x != 0)
				sum1 +=1;
			if(i%y != 0)
				sum2 +=1;
			i++;
		}
		
		
		writer.println((i-1));
		writer.close();
	}

}
class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                     new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    /** get next word */
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                   reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }
    
    static long nextLong() throws IOException{
    	return Long.parseLong( next() );
    }
	
    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }   
}