import java.io.*;
import java.util.*;


public class Main{
	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
		out = new PrintWriter(new BufferedOutputStream(System.out));

		int cnt1 = sc.nextInt();
		int cnt2 = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		
		int max1 = max(cnt1, x);
		int max2 = max(cnt2, y);
		
		if(x * y > cnt1 + cnt2)
		{
			out.println(cnt1 + cnt2);
		}
		else if(max1 / x >= cnt2)
		{
			out.println(max1);
		}
		else if(max2 / y >= cnt1)
		{
			out.println(max2);
		}
		else
		{
			out.println(cnt1 + cnt2 + ((cnt1 + cnt2) / (x * y)));
		}
		out.close();
	}

	public static int max(int cnt, int prime)
	{
		int max = cnt;		
		if(max < prime)
		{
			max = prime;
		}
		
		int sub = max / prime;

		int total = cnt - sub;
		
		int count = 0;
		while(total != cnt)
		{
			max = cnt + sub;
			sub = max / prime;
			total = max - sub;
		}
		return max;
	}

	//-----------PrintWriter for faster output---------------------------------
	public static PrintWriter out;

	//-----------MyScanner class for faster input----------
	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine(){
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}
	//--------------------------------------------------------
}