

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class TestClass {

    public static void main(String[] args) throws IOException {
        
        BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
        String line[]=br.readLine().split(" ");
        
        int cnt1,cnt2,x,y;
        cnt1=Integer.parseInt(line[0]);
        cnt2=Integer.parseInt(line[1]);
        x=Integer.parseInt(line[2]);
        y=Integer.parseInt(line[3]);
        
        System.out.println(solve(cnt1, cnt2, x, y, 1,(int)( Math.pow(10, 18))));
        
    }
    
    
    public static long solve(int cnt1,int cnt2,int x,int y,long low,long high)
    {
        if(low>high)
            return -1;
        
        long mid=(low+high)/2;
        
        long n_d[]=new long[3],g_d[]=new long[2];
        
        n_d[0]=(mid-x)/x+1;
        n_d[1]=(mid-y)/y+1;
        n_d[2]=mid>x*y?((mid-x*y)/(x*y)+1):0;
        
        g_d[0]=n_d[1]-n_d[2];
        g_d[1]=n_d[0]-n_d[2];
        
        long rem=mid-n_d[0]-n_d[1]+n_d[2];
        
        if(rem>=(cnt1-g_d[0]))
        {
            rem-=(cnt1-g_d[0]);
            
            if(rem>=(cnt2-g_d[1]))
            {
                
                long val=solve(cnt1, cnt2, x, y, low, mid-1);
                if(val>0)
                    return val;
                else
                    return mid;
                
            }
            else
            {
                
                 return solve(cnt1, cnt2, x, y, mid+1, high);
            }   
        }
        else
        {
            
             return solve(cnt1, cnt2, x, y, mid+1, high);
        }
        
        
    }
}
