import java.util.Scanner;


public final class b2 {

	public static void main(String[] args) {
		Scanner datain = new Scanner(System.in);
		int c1=datain.nextInt();
		int c2=datain.nextInt();
		int x=datain.nextInt();
		int y=datain.nextInt();
		long res=c1*x/(x-1);
		while(res-res/x>=c1){res--;}res++;
		long r2=res-c1;
		if(r2-r2/y>=c2){System.out.print(res);}
		else{
			res=c2*y/(y-1);
			while(res-res/y>=c2){res--;}res++;
			r2=res-c2;
			if(r2-r2/x>=c1){System.out.print(res);}else{
		long z=x*y;
		long sum=c1+c2;
		res=sum*(z)/(z-1);
		while((res-res/z)>=sum){res--;};res++;
		System.out.print(res);}
		}
	}

}
