/*
 * 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.
 */


import java.util.Scanner;

/**
 *
 * @author Raed
 */
public class FriendsAndPresents {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        
        Scanner input= new Scanner(System.in);
        String rawData = input.nextLine();
        String[] data = rawData.split(" ");
        
        long num1=Long.parseLong(data[0]);
        long num2 =Long.parseLong(data[1]);
        long mod1 =Long.parseLong(data[2]);
        long mod2 =Long.parseLong(data[3]);;
        
         if(num1<num2){
            
            long tempNum= num1;
            num1 = num2;
            num2= tempNum;
            long tempMod= mod1;
            mod1= mod2;
            mod2= tempMod;
        }
         
        long factor = mod1-1;
        long level = (num1-1)/factor;
        long difference = num1 -( level * factor );
        
        long max1 = level*factor + level+difference;
        
        
        long count =0;
        
        
        if(level>=num2){
            System.out.println(max1);
        }
        else{
        
            long remaining = num2-level; //how many numbers left
            
            long factor2 = mod2-1;
            long level2 = (remaining-1)/factor;
            long difference2 = remaining - (level2*factor2);
            long max2 = level2*factor2+level2+difference;
           
            
            if(max2%mod2==0){
            
                max2++;
            }
            
            max2+=max1;
            
            if(max2%mod2==0){
            
                   max2++;
            }
                System.out.println(max2);
        
        }
        
        }
        
        
        
        
        

    
}
