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.

    Find smallest v so that:
        v - D(1,v,x) >= c1
        v - D(1,v,y) >= c2
*/

public class CF483B {

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

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

        int c1 = sc.nextInt();
        int c2 = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();

        int v = c1 + c2;

        while (v-rangeCount(1,v,x) < c1 || v-rangeCount(1,v,y) < c2) {
            v++;
        }

        System.out.println(v);

        sc.close();
    }
}
