import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

 
public class ques1{
     
     
     static InputStream is;
     private static byte[] inbuf = new byte[1024];
     static int lenbuf = 0, ptrbuf = 0;
     static String INPUT = "";
     
     public static void main(String args[]) 
    {
            
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        java.io.PrintWriter out = new java.io.PrintWriter(System.out);
         
      long t1,t2,x,y;
      t1=ln();
      t2=ln();
      x=ln();
      y=ln();
      int i,i1,count1=0,count2=0;
     
          for( i=1;count1!=t1||count2!=t2;i++)
      {
          
          if((i%x)!=0&&count1!=t1)
          {
              count1++;
           //    System.out.println(i);
              continue;
          }
          else if((i%y)!=0&&count2!=t2)
              {
                  count2++;
                //  System.out.println(i);
              
              }
              
      
      }
      count1=0;count2=0;
               for( i1=1;count1!=t1||count2!=t2;i1++)
      {
          
         
           if((i1%y)!=0&&count2!=t2)
              {
                  count2++;
                //  System.out.println(i);
              
              }
         else if((i1%x)!=0&&count1!=t1)
          {
              count1++;
           //    System.out.println(i);
              continue;
          }     
      
      }
      
      
      
      out.println(Math.min(i, i1)-1);
        
         
            out.close();
    
    }
    
     private static int ni()
    {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9')|| b == '-'));
                if(b == '-'){
            minus = true;
            b = readByte();
        }
        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }
      private static long ln()
            {
                    long num = 0, b;
                    boolean minus = false;
                    while((b = readByte()) != -1 && !((b >= '0' && b <= '9')|| b == '-'));
                    if(b == '-'){
                            minus = true;
                            b = readByte();
                    }
                    while(true){
                            if(b >= '0' && b <= '9'){
                                    num = num * 10 + (b - '0');
                            }else{
                                    return minus ? -num : num;
                            }
                            b = readByte();
                    }
            }
     private static int readByte()
    {
        
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }
         private static String str()
            {
                    String num="" ;
                    int b;

                    while((b = readByte()) != -1 && !((b >= 'A' && b <= 'Z')));
                            while(true){
                            if(b >= 'A' && b <= 'Z'){
                                    num=num+(char)b;
                            }else{
                                    return num;
                            }
                            b = readByte();
                    }
            }
 
}