import java.util.*;

public class friendsAndPresents {

	static long cn1, cn2, x, y;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		 cn1 = in.nextLong();
		 cn2 = in.nextLong();
		 x = in.nextLong();
		 y = in.nextLong();
		
		 long left = 1l, right = 1000000000l;
		 
		 while(left < right) {
			 long mid = (left + right) /2;
			 if(check(mid)) {
				 right = mid;
			 } else {
				 left = mid + 1l;
			 }
		 }
		 
		 System.out.println(right);
		
	}
	
	public static boolean check(long v) {
		long f1 = v/x, f2 = v/y, both = v/x/y, other = v - f1 - f2 + both;
		
		long ff1 = f1 - both, ff2 = f2 - both;
		long gf1 = (cn1 - ff2) >= 0 ? cn1- ff2:0;
		long gf2 = (cn2 - ff1) >= 0 ? cn2 - ff1:0;
		
		return (gf1 + gf2) <= other;
	}
}
