import java.util.*;

public class Codeforces273A{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        int cnt1 = in.nextInt(), cnt2 = in.nextInt(), x = in.nextInt(), y = in.nextInt();
        long min = 1;
        while(cnt1 + cnt2 > 1){
            min++;
            if(cnt2 > 0 && min % y > 0) cnt2--;
            else if(cnt1 > 0 && min % x > 0) cnt1--;
        }
        System.out.println(min);
    }
}