import java.io.*;
import java.util.*;
public final class friends_and_presents
{
	static Scanner sc=new Scanner(System.in);
	static PrintWriter out=new PrintWriter(System.out);
	static long maxn=Long.MAX_VALUE-20;
	
	public static void main(String args[]) throws Exception
	{
		int c1=sc.nextInt(),c2=sc.nextInt(),x=sc.nextInt(),y=sc.nextInt(),cnt1=c1,cnt2=c2;
		long max1=0,max2=0;
		Map<Long,Long> m1=new HashMap<Long,Long>(),m2=new HashMap<Long,Long>();
		for(long i=1;i<=maxn;i++)
		{
			if(cnt1>0)
			{
				if(i%x!=0)
				{
					m1.put(i,0L);
					max1=i;
					cnt1--;
				}
			}
			else
			{
				break;
			}
		}
		for(long i=1;i<=maxn;i++)
		{
			Long elem;
			if(cnt2>0)
			{
				if(i%y!=0 && ((elem=(m1.get(i)))==null))
				{
					m1.put(i,0L);
					if(i>max1)
					{
						max1=i;
					}
					cnt2--;
				}
			}
			else
			{
				break;
			}
		}
		cnt1=c2;cnt2=c1;
		for(long i=1;i<=maxn;i++)
		{
			if(cnt1>0)
			{
				if(i%y!=0)
				{
					m2.put(i,0L);
					cnt1--;
					max2=i;
				}
			}
			else
			{
				break;
			}
		}
		for(long i=1;i<=maxn;i++)
		{
			Long elem;
			if(cnt2>0)
			{
				if(i%x!=0 && ((elem=(m2.get(i)))==null))
				{
					m2.put(i,0L);
					cnt2--;
					if(i>max2)
					{
						max2=i;
					}
				}
			}
			else
			{
				break;
			}
		}
		out.println(Math.min(max1,max2));
		out.close();
	}
}