import java.io.*;
import java.util.*;
public class div275Bn
{
	BufferedReader in;
	PrintWriter ob;
	StringTokenizer st;
	int c1,c2,x,y;
	public static void main(String[] args) throws IOException {
		new div275Bn().run();
	}
	void run() throws IOException {
		in=new BufferedReader(new InputStreamReader(System.in));
		ob=new PrintWriter(System.out);
		solve();
		ob.flush();
	}
	void solve() throws IOException {
		c1=ni();
		c2=ni();
		x=ni();
		y=ni();
		long low=0,high=(long)1e18;
		while(high-low>1) {
			long mid=(high+low) >> 1;
			if(fun(mid)) 
				high=mid;
			else
				low=mid;
		}
		ob.println(high);
	}
	boolean fun(long ans) {
		long divx=ans/x;
		long divy=ans/y;
		long both=(ans)/(x*1L*y);
		long remx=divx-both;
		long remy=divy-both;
		long cnt1=c1-(remy);
		long cnt2=c2-(remx);
		long other=ans-divx-divy+both;
		return (cnt1+cnt2<=other);
	}
	int ni() throws IOException {
		return Integer.parseInt(nextToken());
	}
	String nextToken() throws IOException {
		if(st==null || !st.hasMoreTokens())
			st=new StringTokenizer(in.readLine());
		return st.nextToken();
	}
}