import java.util.*;

public final class Test {
	


	public static void main(String[] args) {
		
		int p, q, x, y;
		int ex=0, a=0, b=0;
	 Scanner scn = new Scanner(System.in);
	//System.out.println("hello");
		StringTokenizer st = new StringTokenizer(scn.nextLine());
		x= Integer.parseInt(st.nextToken());
		y= Integer.parseInt(st.nextToken());
		p = Integer.parseInt(st.nextToken());
		q = Integer.parseInt(st.nextToken());
		boolean flag= false;
		int i=1;
		for(;i<100;i++){
			if(i%p!=0 && i%q!=0){
				ex++;
			}
			else if(i%p!=0){
				a++;
			}
			else if(i%q!=0){
				b++;
			}

			if(a+ex >= x && b+ex >= y){
				flag = true; break;
			}
		}
		if(flag)
		System.out.println(i);
	else System.out.println("error");

	}

}

