//package code_24_10_14;

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 a1=((long)(n/a))*x;
	if(n%a==0){a1--;}else{a1+=n%a;}
	long b1=((long)(m/b))*y;
	if(m%b==0){b1--;}else{b1+=m%b;}
	long max=Math.max(a1,b1);
	System.out.println(max);
}
}
