import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.math.BigInteger;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author minhthai
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskB {
    int C1, C2, X, Y;
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        C1 = in.nextInt();
        C2 = in.nextInt();
        X = in.nextInt();
        Y = in.nextInt();

        int ans = Math.min(cal(C1, C2, X, Y), cal(C2, C1, Y, X));

        out.println(ans);
    }

    // find a that there are n numbers <= a and not divide d
    public int find(int n, int d) {
        if(d == 1) return n;
        int rs =  n * d / (d - 1);
        if(rs % d == 0)
            return rs - 1;
        return rs;
    }

    public int cal(int a, int b, int x, int y) {
        int r1 = find(a, x);
        int r2 = r1 - (r1 - r1 / x - r1 / y) - (r1 / x - r1 / (x * y));
        if(r2 >= b)
            return r1;
        return Integer.MAX_VALUE;
    }

}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

}
