import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Solver {

	public static void main(String[] Args) throws NumberFormatException,
			IOException {
		new Solver().Run();
	}

	PrintWriter pw;
	StringTokenizer Stok;
	BufferedReader br;

	public String nextToken() throws IOException {
		while (Stok == null || !Stok.hasMoreTokens()) {
			Stok = new StringTokenizer(br.readLine());
		}
		return Stok.nextToken();
	}

	public int nextInt() throws NumberFormatException, IOException {
		return Integer.parseInt(nextToken());
	}

	public double nextDouble() throws NumberFormatException, IOException {
		return Double.parseDouble(nextToken());
	}

	public long nextLong() throws NumberFormatException, IOException {
		return Long.parseLong(nextToken());
	}

	long cnt1, cnt2, del1, del2;
	
	long gcd(long a, long b){
		while (b>0){
			a=a%b;
			long buf=a;
			a=b;
			b=buf;
		}
		return a;
	}
	
	boolean isPossible(long value, long nok){
		long kolFree=value;
		long kolClosed=kolFree/nok;
		long kolFor1=kolFree/del2-kolClosed;
		long kolFor2=kolFree/del1-kolClosed;
		
		kolFree=kolFree-kolFor1-kolFor2-kolClosed;
		long buf=Math.max(0, cnt1-kolFor1);
		kolFree-=buf;
		if (kolFree<0)
			return false;
		
		return kolFree+kolFor2>=cnt2;
	}
	
	public void Run() throws NumberFormatException, IOException {
		//br = new BufferedReader(new FileReader("input.txt")); pw = new PrintWriter("output.txt");
		br=new BufferedReader(new InputStreamReader(System.in));  pw=new PrintWriter(new OutputStreamWriter(System.out));

		cnt1=nextLong();
		cnt2=nextLong();
		del1=nextLong();
		del2=nextLong();
		long nok=del1*del2/gcd(del1,del2);
		
		long min=1000000;
		long max=2000000;//(long)1e15;
		long mid;
		while (max-min>10){
			mid=(max+min)>>1;
			if (isPossible(mid,nok)){
				max=mid+1;
			} else {
				min=mid-1;
			}
		}
		min=Math.max(min, 1);
		while (!isPossible(min,nok))
			min++;
		
		pw.println(min);
		pw.flush();
		pw.close();
	}

}