import java.util.Scanner;


public class B {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int a = in.nextInt(), b = in.nextInt();
		int x =  in.nextInt(), y = in.nextInt();
		in.close();
		int s = a+b;
		boolean flag = true;
		while (flag) {
			flag = false;
			if (x!=y) {
				int xs = s/x;
				int ys = s/y;
				int an = Math.max(a - ys, 0);
				int bn = Math.max(b - xs, 0);
				int delta = an+bn - (s - xs - ys + xs/y);
				if (delta > 0) {
					flag = true; 
					s += delta;
				}
			} else {
				int xs = s/x;
				int an = a;
				int bn = b;
				int delta = an+bn - (s - xs);
				if (delta > 0) {
					flag = true; 
					s += delta;
				}
			}
		}
		System.out.println(s);
	}
}
