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 = cn1 + cn2, right = 1000000000l;
		 
		 while(left < right) {
			 long mid = (left + right) /2;
			 if(ok(mid)) {
				 right = mid;
			 } else {
				 left = mid + 1;
			 }
		 }
		 
		 System.out.println(left);
		
	}
	
	public static boolean ok(long v) {
		if(v >= Math.max(cn1 + v/x, cn2+v/y))
			return true;
		return false;
	}
	
}
