import java.io.*;
import java.util.*;

/*


*/

public class A {
	static FastReader sc=null;
	
			
	public static void main(String[] args) {
		sc=new FastReader();
		int c1=sc.nextInt(),c2=sc.nextInt(),x=sc.nextInt(),y=sc.nextInt();
		long l=1,r=(long)1e15;
		while(l+1<r) {
			long mid=(l+r)/2;
			if(pos(c1,c2,x,y,mid))r=mid;
			else l=mid;
		}
		System.out.println(r);
		
		
	}
	static boolean pos(int c1,int c2,int x,int y,long v) {
		long tot=v-v/(x+y),cnt1=v-v/x,cnt2=v-v/y;
		
		return tot>=c1+c2 && cnt1>=c1 && cnt2>=c2;
	}
	
	
	
	static int[] ruffleSort(int a[]) {
		ArrayList<Integer> al=new ArrayList<>();
		for(int i:a)al.add(i);
		Collections.sort(al);
		for(int i=0;i<a.length;i++)a[i]=al.get(i);
		return a;
	}
	static void print(int a[]) {
		for(int e:a) {
			System.out.print(e+" ");
		}
		System.out.println();
	}
	
	static class FastReader{
		
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		
		String next() {
			while(!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				}
				catch(IOException e){
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		int[] readArray(int n) {
			int a[]=new int[n];
			for(int i=0;i<n;i++)a[i]=sc.nextInt();
			return a;
		}
	}
}






