import java.util.Scanner;


public class B {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        
        
        
          
            int cnt1 = in.nextInt();
            int cnt2 = in.nextInt();
            int x = in.nextInt();
            int y = in.nextInt();
            int v = cnt1+cnt2;
            while(!a(v,x,y,cnt1,cnt2)){
                v++;
            }
            
            System.out.println(v);
         
                
                
        
        
    }
    
    
    public static boolean a(int v,int x, int y, int cnt1, int cnt2 ){
        
        long mzx = v/x -v/(x*y);
        long mzy = v/y -v/(x*y);
        cnt1 -= mzy;
        cnt2 -= mzx;
        
        if (cnt1<0) {
            cnt1=0;
        }
        if (cnt2<0) {
            cnt2= 0;
        }
        
        long cnt = cnt1+cnt2 - (v - (mzx +mzy));

        boolean ans;
        if(cnt> 0){
            ans =false;
        }
        else{
            ans =true;
        }
        return ans;
        
    }
}
