/* @@@@@@@@@@@@@@@@@@@@@@@
 * @@@ Doston Akhmedov @@@
 * @@@@@@@@@@@@@@@@@@@@@@@
 */

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Locale;
import java.util.StringTokenizer;

public class r_275_b {
	static StringTokenizer st;
	static BufferedReader br;
	static PrintWriter pw;

	static class sort implements Comparable<sort> {
		int a, b;

		public sort(int a, int b) {
			this.a = a;
			this.b = b;
		}

		public int compareTo(sort arg0) {
			if (this.a == arg0.a)
				return (this.b - arg0.b);
			return -(this.a - arg0.a);
		}
	}

	public static void main(String[] args) throws IOException {
		Locale.setDefault(Locale.US);
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
				System.out)));
		// gfile();
		long cnt1=nextLong(),cnt2=nextLong(),x=nextLong(),y=nextLong();
		long t1=(cnt1*x)/(x-1);
		long t2=(cnt2*y)/(y-1);
		long t=t1+t2;
		while((t-t/x>=cnt1&&t/x>=cnt2)||(t-t/y>=cnt2&&t/y>=cnt1)){
			t--;
		}
		pw.print(t+1);
		pw.close();
	}

	private static long gcd(long x, long y) {
		return y==0?x:gcd(y,x%y);
	}

	private static void gfile() throws IOException {
		br = new BufferedReader(new FileReader(new File("input.txt")));
		pw = new PrintWriter(new BufferedWriter(new FileWriter(new File(
				"output.txt"))));
	}

	private static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	private static long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	private static double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	private static String next() throws IOException {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}
}
