
import java.util.Scanner;

public class DumbGifts {

	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		int cnt1 = sc.nextInt();
		int cnt2 = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		
		int z = cnt1+cnt2;
		
		int p=-1;
		int aa = z/(x*y);
		while(p==-1){
		
			p= z/(x*y);
			if(p>aa){
				aa=p; 
				p=-1;
				z=z+aa;
				} 
			
		}
		p = z-cnt1-cnt2;	//divisible by both x & y
		int bx = z/x-p;		//divisible by x but not by y
		int by = z/y-p;		//divisible by y but not by x
		
		//If less than bx/by are required for y & x
		
		if(by - cnt1 > 0 ){
			int ubx = by-cnt1;
			
			int l = x-z%x;
			if(ubx<l) z=z+ubx;
			else{
				ubx = ubx-(l-1);
				z=z+l;
				int m = ubx/x;
					if(ubx%x!=0) z=z+m*x+ubx%x; else z=z+m*x-1;
			}
			/*while(ubx!=0){
				int inc=z+1;
				if(inc%x!=0){z++; ubx--;}
			}*/
		}
		else if(bx-cnt2>0){
			int uby = bx-cnt2;
			
			int l = y-z%y;
			if(uby<l) z=z+uby;
			else{
				uby = uby-(l-1);
				z=z+l;
				int m = uby/y;
					if(uby%y!=0) z=z+m*y+uby%y; else z=z+m*y-1;
			}
			/*while(uby!=0){
				int inc=z+1;
				if(inc%x!=0){z++; uby--;}
			}*/
			
		}
		
		System.out.println(z);
	
	}

}
