

import java.util.PriorityQueue;
import java.util.Scanner;

public class CF483 {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int cnt1 = s.nextInt();
		int cnt2 = s.nextInt();
		int x = s.nextInt();
		int y = s.nextInt();
		int any = 0;

		int last = 0;
		PriorityQueue<Integer> next = new PriorityQueue<Integer>();
		next.add(1);
		while (cnt1 + cnt2 > any) {
			int n = next.remove();
			if (n == last) {
				continue;
			}
			
			next.add(x*n);
			next.add(y*n);
			
			any += n-last-1;
			if (n % x == 0) {
				cnt2 = Math.max(cnt2-1, 0);
			} else {
				cnt1 = Math.max(cnt1-1, 0);
			}
			
			last = n;
		}
		System.out.println(last-(any-cnt1-cnt2)-1);
		s.close();
	}
}
