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

public class Solution {

    private BufferedReader in;
    private PrintWriter out;
    private StringTokenizer st;

    private String next() throws Exception {
        if(st == null || !st.hasMoreElements())
            st = new StringTokenizer(in.readLine());
        return st.nextToken();
    }

    private int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    private long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    private double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }

    private void run() throws Exception {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        // The solution of the problem goes here
        int c1 = nextInt();
        int c2 = nextInt();
        int x = nextInt();
        int y = nextInt();

        long l = 1, r = Long.MAX_VALUE, m = 0;
        while(l < r) {
            m = (l + r) / 2;
            long cx = m / x;
            long cy = m / y;
            long c = m - cx / y - cy / x;
            if (c >= c1 + c2) {
                r = m;
            } else {
                l = m + 1;
            }
        }
        long r1 = r, r2 = r;
        if (r1 - r1 / x < c1) r1 = c1 + r1 / x;
        if (r2 - r2 / y < c2) r2 = c2 + r2 / y;
        r = Math.max(r1, r2);
        out.println(r);
        out.close();
    }

    public static void main(String[] args) throws Exception {
        new Solution().run();
    }
}