import java.io.IOException;
import java.io.InputStreamReader;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.StringTokenizer;
import java.io.InputStream;

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

class TaskB {
	OutputWriter out;
	InputReader in;
	public void solve(int testNumber, InputReader in, OutputWriter out) {
		this.in = in; this.out = out;
		long[] count = new long[2];
		long[] x = new long[2];
		for (int i = 0; i < 2; i++) {
			count[i] = in.readLong();
		}
		for (int i = 0; i < 2; i++) {
			x[i] = in.readLong();
		}
		long low = 1;
		long high = (long)1e18;
		long v = high;
		while (low <= high) {
			long mid = (low + high) / 2;
			if (possible(count, x, mid)) {
				v = mid;
				high = mid - 1;
			} else {
				low = mid + 1;
			}
		}
		out.println(v);
	}
	private boolean possible(long[] count, long[] x, long v) {
		long[] used = new long[2];
		long rem = v;
		for (int i = 0; i < 2; i++) {
			used[i] = v / x[i ^ 1];
			used[i] -= v / (x[i] * x[i ^ 1]);
			rem -= used[i];
		}
		for (int i = 0; i < 2; i++) {
			long diff = Math.max(count[i] - used[i], 0);
			diff = Math.min(diff, rem);
			used[i] += diff;
			if (used[i] < count[i]) {
				return false;
			}
			rem -= diff;
		}
		return true;
	}
}

class OutputWriter {
	private PrintWriter output;
	public OutputWriter(OutputStream out) {
		output = new PrintWriter(out);
	}
	public void println(Object o) {
		output.println(o);
	}
	public void close() {
		output.close();
	}
}

class InputReader {
	private BufferedReader input;
	private StringTokenizer line = new StringTokenizer("");
	public InputReader(InputStream in) {
		input = new BufferedReader(new InputStreamReader(in));
	}
	public void fill() {
		try {
			if(!line.hasMoreTokens()) line = new StringTokenizer(input.readLine());
		} catch(IOException io) { io.printStackTrace(); System.exit(0);}
	}
	public long readLong() {
		fill();
		return Long.parseLong(line.nextToken());
	}
}

