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

public class friends {
	public static void main(String[] args) throws IOException {
		BufferedReader lector = new BufferedReader(new InputStreamReader(
				System.in));
		String[] linea = lector.readLine().split(" ");

		int c1 = Integer.parseInt(linea[0]);
		int c2 = Integer.parseInt(linea[1]);
		int x = Integer.parseInt(linea[2]);
		int y = Integer.parseInt(linea[3]);

		int max = Integer.MAX_VALUE;
		int min = 2;
		int med;
		int px;
		int py;
		int pxy;

		while (max != min) {
			med = (int) (((long) max + min) / 2);

			if (med == min)
				med = max;

			px = med - med/x;
			py = med - med/y;
			pxy = med - med/x - med/y + med/x/y;

			if (px + py - pxy >= c1 + c2 && px >= c1 && py >= c2) {
				if (med == max)
					min = max;
				else
					max = med;
			} else {
				min = med;
			}
		}
		
		System.out.println(min);
	}
}
