import java.util.Scanner;

public class R_275_FriendsAndPresents {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner scan = new Scanner(System.in) ;
        boolean flag1 = false ;
        boolean flag2 = false ;
        int i = 0 ;
        int counter1 = 0 ;
        int counter2 = 0 ;
        int cnt1 = scan.nextInt();
        int cnt2 = scan.nextInt();
        int x = scan.nextInt();
        int y = scan.nextInt();
        //System.out.println(1%2);
        while (!(flag1 && flag2))
        {
        i++ ;
        
        if ((i%x != 0))
            counter1++ ;
        if ((i%y != 0))
            counter2++ ;
        
        if (counter1 == cnt1)
            flag1 = true ;
        if (counter2 == cnt2)
            flag2 = true ;
        //System.out.println(counter1 +"----"+counter2);
        }
        System.out.println(i);
    }

}
