
import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author bektemirov_ri
 */
public class P275B {

    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);
        
        int cnt1 = sc.nextInt();
        int cnt2 = sc.nextInt();
        
        int pr1 = sc.nextInt();
        int pr2 = sc.nextInt();
        
        if (cnt1>cnt2) {
            int temp = cnt1;
            cnt1 = cnt2;
            cnt2 = temp;
            
            temp = pr1;
            pr1 = pr2;
            pr2 = temp;
        }
        
        int cnt1c = 0;
        int cnt2c = 0;
        
        int counter = 0;
        do {
            counter++;
            if (cnt2c < cnt2 && counter%pr2 != 0) {
                cnt2c++;
            } else if (cnt1c < cnt1 && counter%pr1 != 0) {
                cnt1c++;
            } 
            
        } while (cnt1c != cnt1 || cnt2c != cnt2);
        
        System.out.println(counter);
        
    }

}
