import java.util.Scanner;

public class b {
	/*
	 * v>=c1+c2 v-v/x>c1 v-v/y>c2
	 */
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long c1 = sc.nextLong();
		long c2 = sc.nextLong();
		long x = sc.nextLong();
		long y = sc.nextLong();

		long v = c1 + c2;
		System.err.println(( v-v / x) + " " + ( v / y));
		while (v - v / x < c1 || v - v / y < c2) {

			v++;
		}
		v+=v/x/y;
		System.out.println(v);
	}
}