import java.awt.Point;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;

import javax.lang.model.element.NestingKind;
import javax.management.IntrospectionException;
import javax.swing.colorchooser.ColorSelectionModel;
import javax.swing.text.AbstractDocument.LeafElement;
import javax.xml.soap.MimeHeader;
import javax.xml.transform.Templates;

import org.xml.sax.HandlerBase;

import static java.lang.Math.*;

public class Main {

	final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok = new StringTokenizer("");

	void init() throws FileNotFoundException {
		
		if (ONLINE_JUDGE) {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		} else {
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter("output.txt");
		}
	}

	String readString() throws IOException {
		while (!tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	int readInt() throws IOException {
		return Integer.parseInt(readString());
	}

	long readLong() throws IOException {
		return Long.parseLong(readString());
	}

	double readDouble() throws IOException {
		return Double.parseDouble(readString());
	}

	public static void main(String[] args) {
		new Main().run();
		// Sworn to fight and die
	}

	public static void mergeSort(int[] a) {
		mergeSort(a, 0, a.length - 1);
	}
	static int curr = 0;
	static long ans = 0;
	private static void mergeSort(int[] a, int levtIndex, int rightIndex) {
		final int MAGIC_VALUE = 2;
		if (levtIndex < rightIndex) {
			if (rightIndex - levtIndex <= MAGIC_VALUE) {
				insertionSort(a, levtIndex, rightIndex);
			} else {
				int middleIndex = (levtIndex + rightIndex) / 2;
				mergeSort(a, levtIndex, middleIndex);
				ans += curr;
				mergeSort(a, middleIndex + 1, rightIndex);
				ans += curr;
				merge(a, levtIndex, middleIndex, rightIndex);
				ans += curr;
			}
		}
	}
	
	private static void merge(int[] a, int levtIndex, int middleIndex,
			int rightIndex) {
		curr = 0;
		int length1 = middleIndex - levtIndex + 1;
		int length2 = rightIndex - middleIndex;
		int[] levtArray = new int[length1];
		int[] rightArray = new int[length2];
		System.arraycopy(a, levtIndex, levtArray, 0, length1);
		System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);
		for (int k = levtIndex, i = 0, j = 0; k <= rightIndex; k++) {
			if (i == length1) {
				a[k] = rightArray[j++];
			} else if (j == length2) {
				a[k] = levtArray[i++];
			} else {
				if (levtArray[i] > rightArray[j]) curr += middleIndex - i + 1;
				a[k] = levtArray[i] <= rightArray[j] ? levtArray[i++]
						: rightArray[j++];
			}
		}
	}

	private static void insertionSort(int[] a, int levtIndex, int rightIndex) {
		for (int i = levtIndex + 1; i <= rightIndex; i++) {
			int current = a[i];
			int j = i - 1;
			while (j >= levtIndex && a[j] > current) {
				a[j + 1] = a[j];
				j--;
			}
			a[j + 1] = current;
		}
	}

	public void run() {
		try {
			long t1 = System.currentTimeMillis();
			init();
			solve();
			out.close();
			long t2 = System.currentTimeMillis();
			System.err.println("Time = " + (t2 - t1));
		} catch (Exception e) {
			e.printStackTrace(System.err);
			System.exit(-1);
		}
	}

	class LOL implements Comparable<LOL> {

		int x;
		int y;

		public LOL(int x, int y) {
			this.x = x;
			this.y = y;

		}

		@Override
		public boolean equals(Object object) {
			boolean sameSame = false;

			if (object != null && object instanceof LOL) {
				sameSame = ((this.x == ((LOL) object).x) && (this.y == ((LOL) object).y));
			}

			return sameSame;
		}

		@Override
		public int compareTo(LOL o) {

			return (x - o.x); // ---->
			// return o.x * o.y - x * y; // <----
		}

	}

	class test implements Comparable<test> {

		int x;
		int y;

		public test(int x, int y) {
			this.x = x;
			this.y = y;

		}

		@Override
		public int compareTo(test o) {

			return (x - o.x); // ---->
			// return o.x * o.y - x * y; // <----
		}

	}

	public long gcd(long a, long b) {
		if (a % b == 0)
			return b;
		else
			return gcd(b, a % b);
	}

	public int gcd(int a, int b) {
		if (a % b == 0)
			return b;
		else
			return gcd(b, a % b);
	}

	boolean prime(int n) {
		for (int i = 2; i <= sqrt(n); i++)
			if (n % i == 0)
				return false;
		return true;
	}

	Map<Integer, List<Integer>> g, gf;
	boolean[] color;
	HashMap<Integer, Boolean> compColor;
	ArrayList<Integer> order, component;
	List<Integer> answer;
	ArrayList<ArrayList<Integer>> graph;

	public void dfs1(Integer v) {
		color[v] = true;
		if (!g.containsKey(v)) {
			order.add(v);
			return;
		}
		for (int i = 0; i < g.get(v).size(); i++) {
			if (!color[(g.get(v).get(i))]) {
				dfs1(g.get(v).get(i));
			}
		}
		order.add(v);
	}

	public void dfs2(Integer v) {
		color[v] = true;
		if (!gf.containsKey(v)) {
			component.add(v);
			return;
		}
		component.add(v);
		for (int i = 0; i < gf.get(v).size(); i++) {
			if (!color[(gf.get(v).get(i))]) {
				dfs2(gf.get(v).get(i));
			}
		}
	}

	int goal;
	boolean isFind = false;

	public void dfs(Integer v) {
		color[v] = true;
		if (v == goal) {
			isFind = true;
			answer.add(v);
			return;
		}
		for (int i = 0; i < g.get(v).size(); i++) {
			if (!color[(g.get(v).get(i))]) {
				dfs(g.get(v).get(i));
				if (isFind) {
					answer.add(v);
					return;

				}
			}
		}
	}
	
	

	public void solve() throws IOException {
		int cnt1 = readInt();
		int cnt2 = readInt();
		
		int x = readInt();
		int y = readInt();
		
		
		
		if (cnt2 > cnt1) {
			int k = cnt2;
			cnt2 = cnt1;
			cnt1 = k;
			
			int temp = x;
			x = y;
			y = temp;
		}

		long i = 0;
		long iMax = 0;
		long jMax = 0;
		while (cnt1 > 0 || cnt2 > 0) {
			i++;
			if (i % x != 0 && cnt1 > 0) {
					iMax = i;
					cnt1--;
			} else if (i % y != 0 && (cnt2 > 0)) {
					jMax = i;
					cnt2--;
			}
		}
		
		out.print(max(iMax, jMax));
	}
}