import java.util.Scanner;

public class CF483B{
    static int bs(int cnt1, int cnt2, int x, int y){
        int l = cnt1+cnt2;
        int r = 2*l;
        while (l<r){
            int mid = (l+r)/2;
            int valid1 = mid-mid/x;
            int valid2 = mid-mid/y;
            int sum = mid-mid/x/y;
            if (valid1<cnt1||valid2<cnt2||sum<cnt1+cnt2){
                l = mid+1;
            } else {
                r = mid-1;
            }
        }
        return l;
    }

    public static void main(String[] args){
        Scanner scn = new Scanner(System.in);
        while (scn.hasNext()){
            int cnt1 = scn.nextInt();
            int cnt2 = scn.nextInt();
            int x = scn.nextInt();
            int y = scn.nextInt();
            System.out.println(bs(cnt1, cnt2, x, y));
        }
    }
}