import java.io.*;
import java.util.*;

public class Template implements Runnable {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws FileNotFoundException {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine(), " :");
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    int[] readIntArray(int size) throws IOException {
        int[] res = new int[size];
        for (int i = 0; i < size; i++) {
            res[i] = readInt();
        }
        return res;
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    <T> List<T>[] createGraphList(int size) {
        List<T>[] list = new List[size];
        for (int i = 0; i < size; i++) {
            list[i] = new ArrayList<>();
        }
        return list;
    }

    public static void main(String[] args) {
        new Template().run();
        // new Thread(null, new Template(), "", 1l * 200 * 1024 * 1024).start();
    }

    long timeBegin, timeEnd;

    void time() {
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    long memoryTotal, memoryFree;

    void memory() {
        memoryFree = Runtime.getRuntime().freeMemory();
        System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10)
                + " KB");
    }

    public void run() {
        try {
            timeBegin = System.currentTimeMillis();
            memoryTotal = Runtime.getRuntime().freeMemory();
            init();
            solve();
            out.close();
            if (System.getProperty("ONLINE_JUDGE") == null) {
                time();
                memory();
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    long cnt(long l, long r, long div) {
        r = r / div * div;
        l = (l + div - 1) / div * div;
        if (l > r) return 0;
        return (r - l) / div + 1;
    }

    void solve() throws IOException {
        int cnt1 = readInt();
        int cnt2 = readInt();
        int x = readInt();
        int y = readInt();

        long l = 1;
        long r = (long) 1e11;
        long answer = 0;
        while (l <= r) {
            long mid = (l + r) >> 1;

            long dividedToX = cnt(1, mid, x);
            long dividedToY = cnt(1, mid, y);
            long dividedToXY = cnt(1, mid, x * y);

            dividedToX -= dividedToXY;
            dividedToY -= dividedToXY;

            long need1 = Math.max(0, cnt1 - dividedToY);
            long need2 = Math.max(0, cnt2 - dividedToX);

            if (need1 + need2 <= mid - dividedToX - dividedToY + dividedToXY) {
                answer = mid;
                r = mid - 1;
            } else {
                l = mid + 1;
            }
        }
        out.println(answer);
    }

}