import java.util.Scanner;

/*
    Problem: Find the mininum number of consecutive values v,
    such that c1 numbers are not even divisible by x
    and c2 numbers are not even divisible by y

    and the numbers in c1 and c2 are distinct.
*/

/*
    Solution:

    lower bound (c1 + c2) - need to generate at least c1+c2 distinct values

    In a range [a,b], how many numbers are divisible by x?
    DC(a,b,x) = x/b - x/a + (a % x == 0 ? 1 : 0)
    DC(a,b,n) = number of numbers between a and b inclusive, evenly div by n

    upper bound
    DC(a,b,x)   - Numbers divisible by x in the range [a,b]
    DC(a,b,y)   - Numbers divisible by y in the range [a,b]

    x and y are prime numbers, so they have no common factors.

    X is the set of all numbers divisible by x
    Y is the set of all numbers divisible by y

    only Friend 1: |Y| = Dc(1,v,y)
    only Friend 2: |X| = Dc(1,v,x)
    not only Friend 1: v - |Y|
    noy only Friend 2: v - |X|
    Neither: |X n Y| = Dc(1,v,xy)
    Either: |~X n ~Y| = |~(X u Y)| = v - |X u Y| =
        v - (|X| + |Y| - |X n Y|)

    we have enough when
    r1 = max(c1 - onlyF1, 0)
    r2 = max(c2 - onlyF2, 0)
    r1 + r2 - either <= 0
*/

public class CF483B {

    public static long dc(long a, long b, long d) {
        return b/d - a/d + (a % d == 0 ? 1 : 0);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        long c1 = sc.nextLong();
        long c2 = sc.nextLong();
        long x = sc.nextLong();
        long y = sc.nextLong();

        long min = c1 + c2;
        long max = Long.MAX_VALUE;
        long mid = (max + min)/2;

        while (max >= min) {
            mid = (max + min)/2;

            long notF2 = dc(1,mid,y);
            long notF1 = dc(1,mid,x);
            long neither = dc(1,mid,x*y);
            long either = mid - (notF1 + notF2 - neither);
            long uniqF1 = notF2 - neither;
            long uniqF2 = notF1 - neither;
            long r1 = Math.max(0, c1 - uniqF1);
            long r2 = Math.max(0, c2 - uniqF2);

            if (r1 + r2 <= either) { // valid, look for smaller
                max = mid - 1;
            }
            else { // need to be bigger
                min = mid + 1;
            }
        }

        System.out.println(mid);

        sc.close();
    }
}
