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

public class Div275FriendsAndPresents {	
	public static void main(String[] args) throws Exception {
		// Set to false while uploading.
		boolean debug = false;

		// If debug, read from file.
		InputStream inputStream = debug ? new FileInputStream("input.txt") : System.in;
		OutputStream outputStream = System.out;

		// Run the solver.
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Solver solver = new Solver();
		solver.solve(in, out);
		out.close();
	}

	static class Solver {
		int cnt0, cnt1;
		int x, y;
		
		private boolean isOk(int v) {
			int nx = v / x;
			int ny = v / y;
			int nboth = v / (x * y);
			
			int r0 = cnt0 - (ny - nboth);
			int r1 = cnt1 - (nx - nboth);
			
			return (Math.max(0, r0) + Math.max(0, r1) <= v - nx - ny + nboth);
		}
		
		public void solve(InputReader in, PrintWriter out) {
			cnt0 = in.nextInt();
			cnt1 = in.nextInt();
			x = in.nextInt();
			y = in.nextInt();
			
			int l = 0;
			int r = (int) 1E+18;
			
			while (r - l > 1) {
				int mid = (l + r) >> 1;
				if (isOk(mid)) {
					r = mid;
				} else {
					l = mid;
				}
			}
			
			System.out.println(r);
		}
	}

	static class InputReader {
		private final BufferedReader reader;
		private StringTokenizer tokenizer;

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

		private void tokenize() {
			tokenizer = new StringTokenizer(nextLine());
		}
		
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				tokenize();
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public int[] nextIntArray() {
			tokenize();
			int count = tokenizer.countTokens();
			int[] array = new int[count];
			for (int i = 0; i < count; i++) {
				array[i] = Integer.parseInt(tokenizer.nextToken());
			}
			return array;
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}
