import java.util.Scanner;

public class B {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int cnt1 = scanner.nextInt();
		int cnt2 = scanner.nextInt();
		int x = scanner.nextInt();
		int y = scanner.nextInt();
		scanner.close();
		
		long low = 2, high = Integer.MAX_VALUE;
		long res = -1;
		while(low < high) {
			long mid = (low + high) / 2;
			long n1 = mid - mid / x;
			long n2 = mid - mid / y;
			long n3 = n1 + n2 - (mid - mid / (x * y));
			n1 = n1 - n3;
			n2 = n2 - n3;
			if(n1 + n3 >= cnt1 && n2 + n1 + n3 - cnt1 >= cnt2) {
				res = mid;
				high = mid;
			} else
				low = mid + 1;
				
		}
		System.out.println(res);
	}
}