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

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 aux1;
		int aux2;

		while (max != min) {
			med = (int) (((long) max + min) / 2);
			aux1 = c1;
			aux2 = c2;

			if (med == min)
				med = max;

			for (int i = med; i > 0; i--) {
				if (i % x != 0 && aux1 > 0)
					aux1--;
				else if (i % y != 0 && aux2 > 0)
					aux2--;
				if (aux1==0 && aux2==0)
					break;
			}

			if (aux1 == 0 && aux2 == 0) {
				if (med == max)
					min = max;
				else
					max = med;
			} else {
				min = med;
			}
		}
		
		System.out.println(min);
	}
}
