import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class MainB {
	MyScanner sc = new MyScanner();
	Scanner sc2 = new Scanner(System.in);
	final int MOD = 1000000007;
	int[] dx = { 1, 0, 0, -1 };
	int[] dy = { 0, 1, -1, 0 };
	int M = 3000000;

	void run() {
		boolean[] prime = new boolean[M + 1];
		Arrays.fill(prime, true);
		prime[0] = prime[1] = false;
		for (int i = 2; i * i <= M; i++) {
			if (!prime[i]) {
				continue;
			} else {
				for (int j = i * 2; j <= M; j += i) {
					prime[j] = false;
				}
			}
		}
		int cnt1 = sc.nextInt();
		int cnt2 = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		boolean[] use = new boolean[M + 1];
		int c1 = 0;
		int c2 = 0;
		ArrayList<Integer> list1 = new ArrayList<Integer>();
		ArrayList<Integer> list2 = new ArrayList<Integer>();
		for (int i = 1;; i++) {
			if (c1 == cnt1) {
				break;
			}
			if (i % x != 0) {
				c1++;
				list1.add(i);
				use[i] = true;
			}
		}
		for (int i = 1;; i++) {
			if (c2 == cnt2) {
				break;
			}
			if (i % y != 0 && !use[i]) {
				c2++;
				list2.add(i);
				use[i] = true;
			}
		}
		ArrayList<Integer> list3 = new ArrayList<Integer>();
		ArrayList<Integer> list4 = new ArrayList<Integer>();
		c1 = 0;
		c2 = 0;
		Arrays.fill(use, false);
		for (int i = 1;; i++) {
			if (c2 == cnt2) {
				break;
			}
			if (i % y != 0) {
				c2++;
				list3.add(i);
				use[i] = true;
			}
		}
		for (int i = 1;; i++) {
			if (c1 == cnt1) {
				break;
			}
			if (i % x != 0 && !use[i]) {
				c1++;
				list4.add(i);
				use[i] = true;
			}
		}
		int max1 = Math.max(list1.get(list1.size() - 1),
				list2.get(list2.size() - 1));
		int max2 = Math.max(list3.get(list3.size() - 1),
				list4.get(list4.size() - 1));
		if (list1.size() == 0 || list2.size() == 0) {
			System.out.println(max2);
		} else if (list3.size() == 0 || list4.size() == 0) {
			System.out.println(max1);
		} else {
			System.out.println(Math.min(max1, max2));
		}
	}

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

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	void debug2(int[][] array) {
		for (int i = 0; i < array.length; i++) {
			for (int j = 0; j < array[i].length; j++) {
				System.out.print(array[i][j]);
			}
			System.out.println();
		}
	}

	class MyScanner {
		int nextInt() {
			try {
				int c = System.in.read();
				while (c != '-' && (c < '0' || '9' < c))
					c = System.in.read();
				if (c == '-')
					return -nextInt();
				int res = 0;
				do {
					res *= 10;
					res += c - '0';
					c = System.in.read();
				} while ('0' <= c && c <= '9');
				return res;
			} catch (Exception e) {
				return -1;
			}
		}

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

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

		String next() {
			try {
				StringBuilder res = new StringBuilder("");
				int c = System.in.read();
				while (Character.isWhitespace(c))
					c = System.in.read();
				do {
					res.append((char) c);
				} while (!Character.isWhitespace(c = System.in.read()));
				return res.toString();
			} catch (Exception e) {
				return null;
			}
		}
	}
}
