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();
        int l = 1, r = Integer.MAX_VALUE >> 1, m;
        while(l < r){
            m = (l + r) >> 1;
            if(cnt1 <= m - m / x && cnt2 <= m - m / y && cnt1 + cnt2 <= m - m / x / y){
                r = m;
            } else {
                l = m + 1;
            }
        }
        System.out.println(r);
    }
}