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();

        long ans = binS();
        out.println(ans);
    }

    // do binary search
    public long binS() {
        long low = 1, hi = C1 * X / (X - 1) + C2 * Y / (Y - 1);
        long ans = Integer.MAX_VALUE;
        while(low <= hi) {
            long mid = (low + hi) / 2;
            if (f(mid)) {
                if(mid < ans)
                    ans = mid;
                hi = mid - 1;
            }
            else
                low = mid + 1;
        }
        return ans;
    }

    public boolean f(long x) {
        long s1 = x / Y - x/(X * Y);
        long s2 = x / X - x/(X * Y);
        long rest = Math.max(0, C1 - s1) + Math.max(0, C2 - s2);
        if(x - x/X - x/Y + x/(X * Y) >= rest)
            return true;
        return false;
    }

}

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());
    }

}
