import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.Vector;


public class hazem {
	static int n1,n2,p1,p2 ;

	public static void main(String[] args) throws IOException{
		
		FastScanner sc = new FastScanner();
	    PrintWriter out = new PrintWriter(System.out);
	    n1=sc.nextInt(); 
	    n2=sc.nextInt();
	    p1=sc.nextInt();
	    p2=sc.nextInt();
	    int lo=0;int hi=1000000000;
	    int ans=0;
	    int mid=0;
	    for(int i=1;i<=100 ;i++){
	    	mid=(lo+hi)>>1 ;
	    //System.out.println(mid);
	    if(valid(mid)){
	    	hi=mid-1;
	    	ans=mid;
	    }
	    else
	    	lo=mid+1;
	   
	    	
	    	
	    	
	    }
	    System.out.println(ans);
	   
	
	
}
	public static boolean valid(int n){
		
		int total = n - n/p1 - n/p2 + n/(p1*p2);
		int divp1 =n/p1; 
		int divp2= n/p2 ;
		divp2 -= n1;
		if(divp2<0)
			total+=divp2;
		if(total<0)
			return false;
		total+=divp1;
		if(total<n2)
			return false;
		
		return true;	
		
	
		
		
		
		
		
	}
	
	    
	    
	    
}

	


	
	

	
	



	    	
	
 	


	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
  

	  
	   
	    	
	    	
	 
	    
	    
	    		
	  	
	    	
	    	
	 
	 















class FastScanner {




    BufferedReader br;
    StringTokenizer st;

    public FastScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    public FastScanner(String s) {
        try {
            br = new BufferedReader(new FileReader(s));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    String nextToken() {
        while (st == null || !st.hasMoreElements()) {
            try {
            	
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(nextToken());
    }

    long nextLong() {
        return Long.parseLong(nextToken());
    }

    double nextDouble() {
        return Double.parseDouble(nextToken());
    }
 
  
}