import java.util.Scanner;

public class B {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long c1 = in.nextLong(), c2 = in.nextLong(), x = in.nextLong(), y = in
				.nextLong();

		long cc1 = 0l, cc2 = 0l, v1 = 1, v2 = 1;
		while (cc1 + x - 1 < c1) {
			cc1 += x - 1;
			v1 = x;
		}
		v1 += ((c1 - cc1));
		v2 = v1 + 1;
		while (cc2 + y - 1 < c2) {
			cc2 += y - 1;
			v2 = y;
		}
		v2 += ((c2 - cc2));
		System.out.println(Math.max(v2, v1));
		in.close();
	}

}