import java.io.BufferedInputStream;
import java.io.IOException;
import java.util.Scanner;

public class B {

	public static void main(String[] xa) throws IOException {
		Scanner sc = new Scanner(new BufferedInputStream(System.in));
		long c1 = sc.nextLong();
		long c2 = sc.nextLong();

		int x = sc.nextInt();
		int y = sc.nextInt();

		long left = c1 + c2 - 1;
		long right = Long.MAX_VALUE;
		while (left < right) {
			long mid = left + ((right - left) / 2);
			if (worksOut(c1, x, c2, y, mid)) {
				right = mid;
			} else {
				left = mid + 1;
			}
		}
		System.out.println(left);

	}

	static boolean worksOut(long c1, int x, long c2, int y, long guess) {
		long numbersForOne = guess - guess / x;
		long numbersForTwo = guess - guess / y;

		// case one
		long numbersForOneIfOneAdjusts = numbersForOne
				- ((guess / y) - guess / (x * y));
		long numbersForTwoIfTwoAdjusts = numbersForTwo
				- ((guess / x) - guess / (x * y));

		return (numbersForOneIfOneAdjusts >= c1 && numbersForTwo >= c2)
				|| (numbersForOne >= c1 && numbersForTwoIfTwoAdjusts >= c2);
	}
}