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.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;
 public   class Main {
    static class Reader
    {
    BufferedReader r;
    StringTokenizer str;
    Reader()
    {
    r=new BufferedReader(new InputStreamReader(System.in));
    }
    Reader(String fileName) throws FileNotFoundException
    {
    r=new BufferedReader(new FileReader(fileName));
    }
    public String getNextToken() throws IOException
    {
    if(str==null||!str.hasMoreTokens())
    {
    str=new StringTokenizer(r.readLine());
    }
    return str.nextToken();
    }
    public int nextInt() throws IOException
    {
    return Integer.parseInt(getNextToken());
    }
    public long nextLong() throws IOException
    {
    return Long.parseLong(getNextToken());
    }
    public Double nextDouble() throws IOException
    {
    return Double.parseDouble(getNextToken());
    }
    public String nextString() throws IOException
    {
    return getNextToken();
    }
    public int[] intArray(int n) throws IOException
    {
        int a[]=new int[n];
        for(int i=0;i<n;i++)
            a[i]=nextInt();
        
        return a;
        
    }
    public long[] longArray(int n) throws IOException
    {
        long a[]=new long[n];
        for(int i=0;i<n;i++)
            a[i]=nextLong();
        
        return a;
        
    }
    public String[] stringArray(int n) throws IOException
    {
        String a[]=new String[n];
        for(int i=0;i<n;i++)
            a[i]=nextString();
        
        return a;
        
    }
    public int gcd(int a, int b) {
if(b == 0){
return a;
}
return gcd(b, a%b);
}
    }
    
    public static void main(String args[]) throws IOException{
       Reader r=new Reader();
       PrintWriter pr=new PrintWriter(System.out,false);
      
int cnt1=r.nextInt();
int cnt2=r.nextInt();
int x=r.nextInt();
int y=r.nextInt();
pr.println(Math.min(fun(cnt1,cnt2,x,y),fun(cnt2,cnt1,y,x)));




      
     pr.flush();
     pr.close();
    }
  
   public static int fun(int cnt1,int cnt2,int x,int y)
   {
      


int sum=0;

sum+=(cnt1/(x-1))*x;

sum+=cnt1%(x-1);


int left=cnt1/(x-1);


int prod=x*y;

left-=sum/prod;


cnt2-=left;

if(cnt2<=(y-(sum%y)-1))
{
    
    sum+=cnt2;
    cnt2=0;
    return sum;
}
else
{
    
    cnt2-=(y-(sum%y)-1);
    sum+=y-(sum%y);
   
    sum+=(cnt2/(y-1))*y;

sum+=cnt2%(y-1);
    if(cnt2%(y-1)==0)
        sum--;
    return sum;
}
       
       
       
   }
     
 } 