
import java.util.Scanner;

public class B_vali {
public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	long n=sc.nextLong();
	long m=sc.nextLong();
	long x=sc.nextLong();
	long y=sc.nextLong();
	long a=x-1;
	long b=y-1;
	long c=((long) n/a)*x;
	m-=(long)c/x-(long)c/(x*y);
	long d=((long)(m/b))*y;
	c=c+d;
	if(n%a==0){c--;}else{c+=n%a;}
	if(m%b!=0){
		m=m%b;
		for (long i =1; i<=b; i++) {
			if((c+i)%x!=0){
				m--;
				if(m==0){
					System.out.println(c+i);
					return;
				}
			}
		}
	}
	System.out.println(c);
	
}
}
