import java.util.Scanner;

public class B {
    static long cnt1, cnt2, x, y, xy;

    static boolean check(long mid) {
        long count = mid - (mid / xy);
        count = count - (mid / x);
        if (count >= cnt1) {
            long c2 = mid / x;
            count = count - Math.max(cnt1, (mid / y));
            if (count >= cnt2 - c2)
                return true;
        }
        return false;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        cnt1 = sc.nextLong();
        cnt2 = sc.nextLong();
        x = sc.nextLong();
        y = sc.nextLong();
        xy = x * y;
        // long lo = cnt1 + cnt2;
        // long hi = 1000000000000000000L;
        long lo = 0;
        long hi = 1000000000000000000L;
        while (lo < hi) {
            long mid = (lo + hi) / 2;
            if (check(mid)) {
                hi = mid - 1;
            } else {
                lo = mid + 1;
            }
        }
        if (check(hi))
            System.out.println(hi);
        else {
            System.out.println(hi + 1);
        }
    }
}
