import java.util.Scanner;

public class CF275B {
    public static void main(final String[] args) {

        Scanner sc = new Scanner(System.in);

        long finish = System.currentTimeMillis();

        int cnt1 = sc.nextInt();
        int cnt2 = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();

        if (cnt1 < cnt2) {
            int tmp = cnt1;
            cnt1 = cnt2;
            cnt2 = tmp;
            tmp = x;
            x = y;
            y = tmp;
        }

        int minNum = 0;
        int xPrev = 0;
        int xNext = x;
        while (cnt1 > 0) {
            if (xNext - xPrev - 1 >= cnt1) {
                minNum = xPrev + cnt1;
                break;
            }

            cnt2--;
            cnt1 -= x - 1;
            xNext += x;
            xPrev += x;
        }

        if (cnt2 <= 0) {
            System.out.println(minNum);
            return;
        } else {
            int factor = (minNum / y);
            int yPrev = factor * y;
            int yNext = (factor + 1) * y;

            if (yNext - minNum - 1 >= cnt2) {
                minNum += cnt2;
            } else {
                cnt2 -= (yNext - minNum - 1);
                yPrev += y;
                yNext += y;
                while (cnt2 > 0) {
                    if (yNext - yPrev - 1 >= cnt2) {
                        minNum = yPrev + cnt2;
                        break;
                    }

                    cnt2 -= y - 1;
                    yNext += y;
                    yPrev += y;

                }
            }
        }

        System.out.println(minNum);
    }
}
