import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


public class problemb {
public static void main(String[] args) throws NumberFormatException, IOException {
    BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int a = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());
        int x = Integer.parseInt(st.nextToken());
        int y = Integer.parseInt(st.nextToken());
        long sum1 =0;
        long sum2 = 0;
        if(a>b){
            int x1 = x-1;
            int need1 = a/x1;
            int i = (need1*x)-1;
            if(a%x1==0){
                b-=(need1-1);
            }else{
                i=(need1*x)+(a%x1);
                b-=(need1);

            }
            while(b>0){
                i++;
                if(i%y!=0){
                    b--;
                }
                
            }
            System.out.println(i);

        }else{
            int y1 = y-1;
            int need2 = b/y1;
            int i = (need2*y)-1;
            if(b%y1==0){
                a-=(need2-1);
            }else{
                i=(need2*y)+(b%y1);
                a-=(need2);

            }
            while(a>0){
                i++;
                if(i%x!=0){
                    a--;
                }
            }
            System.out.println(i);


        }


}
}
