import java.util.*;

public class Main {
	static int cnt1, cnt2, x, y;

	static boolean check(int p) {
		int a = p / x;
		int b = p / y;
		int c = p / (x * y);
		if (cnt1 <= p - a && cnt2 <= p - b && cnt1 + cnt2 <= p - c) {
			return true;
		} else {
			return false;
		}
	}

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		cnt1 = scan.nextInt();
		cnt2 = scan.nextInt();
		x = scan.nextInt();
		y = scan.nextInt();
		int an = 0;
		int left = 1;
		int right = (int)Math.pow(10,9)+5;
		int mid = 0;
		while (left < right) {
			mid = (left + right) / 2;
			if (check(mid)) {
				an = mid;
				right = mid;
			} else {
				left = mid + 1;
			}
		}
		System.out.println(an);
	}
}

 		 	 		  							     	 		 	