
import java.util.*;
public class Main {

	

	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 r = 20000000000l;
		long l=0;
		long mid = 0;
		while(l+1<r)
		{
			mid=(l+r)/2;
			long m = mid/x;
			long n = mid/y;
			long q = m*n/gcd(m,n);
			long c = mid-m-n+q;
			if(n<=a)
				c-=(a-n);
			if(m<=b)
				c-=(b-m);
			if(c<0)
				l=mid;
			else
				r=mid;
				
		}
		System.out.println(r);

	}
	static long gcd(long a,long b)
	{
		if(b==0)
			return a;
		return gcd(b,a%b);
	}
	

}

  	   		  	   	 		 	  		   		