import java.util.Scanner;


public class B483 {
	
	private int min = 0;
	int[] arr1;
	int[] arr2;
	int d1;
	int d2;
	int al1;
	int al2;
	int arr1c;
	int arr2c;
	
	public static void main(String[] args) {
	
		B483 obj = new B483();
		obj.init();
		obj.compute();
		System.out.println(obj.min);
	}
	
	private void init() {
		Scanner scn = new Scanner(System.in);
		String ip = scn.nextLine();
		
		al1=Integer.parseInt(ip.split(" ")[0]);
		al2=Integer.parseInt(ip.split(" ")[1]);
		d1=Integer.parseInt(ip.split(" ")[2]);
		d2=Integer.parseInt(ip.split(" ")[3]);
		
		arr1 = new int[al1];
		arr2 = new int[al2];
	}
	
	private void compute() {
		int mini = 0;
		for(int i=al1+al2;i<=Integer.MAX_VALUE;i++)
		{
			arr1c=arr1.length;
			arr2c=arr2.length;
			int diff = check(i);
			if(diff == 0)
			{
				mini = i;
				break;
			}
			
			i += diff-1;
				
		}
		min = mini;
	}
	
	private int check(int vic) {
		Boolean flag=false;
		int diff = 0;
		int i;
		for(i=vic;i>0;i--)
		{
			if(i%d1!=0 && i%d2!=0)
			{
				if(arr1c>arr2c)
				{
					if(arr1c!=0)
					{
						arr1c--;
						
					}
					
					if(arr1c>=0)
					{
						arr1[arr1c]=i;
						
					}
				}
				else
				{
					if(arr2c!=0)
					{
						arr2c--;
						
					}
					
					if(arr2c>=0)
					{
						arr2[arr2c]=i;
						
					}
				}
			}
			else if(i%d1!=0)
			{
				if(arr1c!=0)
				{
					arr1c--;
					
				}
				
					
				if(arr1c>=0)
				{
					arr1[arr1c]=i;
					
				}
			}
			else if(i%d2!=0)
			{
				if(arr2c!=0)
				{
					arr2c--;
					
				}
					
				if(arr2c>=0)
				{
					arr2[arr2c]=i;
					
				}
			}
			/*else
			{
				break;
			}*/
		}
		
		if(i==0 && arr1c==0 && arr2c==0)
		{
			flag=true;
			diff = 0;
		}else if(i==0 && arr1c==0)
		{
			diff = arr2c;
		}else if(i==0 && arr2c==0)
		{
			diff = arr1c;
		}
		
		return diff;
	}
}
