import java.io.*;
import java.util.*;
public class div275Bnew
{
	BufferedReader in;
	PrintWriter ob;
	StringTokenizer st;
	public static void main(String[] args) throws IOException {
		new div275Bnew().run();
	}
	void run() throws IOException {
		//in=new BufferedReader(new FileReader("input.txt"));
		in=new BufferedReader(new InputStreamReader(System.in));
		ob=new PrintWriter(System.out);
		solve();
		ob.flush();
	}
	void solve() throws IOException {
		long c1=nl();
		long c2=nl();
		long x=nl();
		long y=nl();
		long tot=c1+c2;
		long divx=tot/x;
		long divy=tot/y;
		long divboth=tot/(x*1L*y);
		long remx=tot-divx-divboth;
		long remy=tot-remx;
		long ux=tot;
		long uy=tot;
		while(remx<c1) {
			ux+=1;
			if(ux%x!=0)
				++remx;
		}
		long extra=(remx-c1);
		while(remy+extra<c2) {
			uy+=1;
			if(uy%y!=0)
				++remy;
		}
		ob.print(Math.max(ux,uy));
	}
	String ns() throws IOException {
		return nextToken();
	}
	long nl() throws IOException {
		return Long.parseLong(nextToken());
	}
	int ni() throws IOException {
		return Integer.parseInt(nextToken());
	}
	double nd() throws IOException {
		return Double.parseDouble(nextToken());
	} 
	String nextToken() throws IOException {
		if(st==null || !st.hasMoreTokens())
			st=new StringTokenizer(in.readLine());
		return st.nextToken();
	}
}