
import java.util.*;
public class Main {

	static long r = 20000000000l;
	static long l=3;
	static int a; 
	static int b;
	static int x; 
	static int y;
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int x = scan.nextInt();
		int y = scan.nextInt();
		
		long mid = 0;
		while(l<r)
		{
			mid=(l+r)/2;
			long m = mid/x;
			long n = mid/y;
			long c = mid-m-n;
			if(n<a)
				c-=(a-n);
			if(m<b)
				c-=(b-m);
			if(c<0)
				l=mid;
			if(c>0)
				r=mid;
			if(c==0)
				break;
				
		}
		System.out.println(mid);

	}

}

	 	 				     		 			 	 			 	   	