import java.util.Scanner;


public class Principale {


    public static void main(String[] args) {

            Scanner sc= new Scanner(System.in);
        
            String a = sc.nextLine();


            int i=0;
            int j=i;
            while (a.charAt(i)!=' '){
                  i+=1;
                
            }
            String ch=a.substring(j,i);
            
            
            int cnt1 = Integer.parseInt(ch);
            
            j=i+1;
            i+=1;
            
            while (a.charAt(i)!=' '){
                
                  i=i+1;
                  
            }
            ch=a.substring(j,i);
            
            int cnt2=Integer.parseInt(ch);
            
            j=i+1;
            i+=1;
            while (a.charAt(i)!=' '){
            
                  i+=1;
            }
            
            ch=a.substring(j,i);
            
            int x=Integer.parseInt(ch);
            j=i+1;
            
            ch=a.substring(j,a.length());
            int y=Integer.parseInt(ch);
            

            /*test*/
            boolean test=false;
            if(1<=cnt1 && cnt2 <= Math.pow(10,9) && 
                    cnt1+cnt2<= Math.pow(10, 9) && 2 <= x 
                      && x <= y && y<= 3*(Math.pow(10,4))) {
                
                  test = true;
            }
            /* cherche */
            int [] tab1=new int[cnt1];
            int [] tab2=new int[cnt2];
            j=1;
            for(i=0;i<cnt1;i++){
                
                  while(j%x==0){
                      j++;
                  }
                 
                  tab1[i]=j;
                  j++; 
            }
            j=1; 
            for(i=0;i<cnt2;i++){
                
                  while(j%y==0){
                       j=j+1;
                         
                  }
                  tab2[i]=j;
                 
                  j++;
            }
            /*end cherche*/
            /*grand*/
            j=tab1[0];
            
            for(i=1;i<cnt1;i++){
                
                  if(tab1[i]>j){
                      j= tab1[i];
                  } 
            }
            for(i=0;i<cnt2;i++){
                
                  if(tab2[i]>j){
                      j=tab2[i];
                  }
                  
            }
            /*end grand*/
            System.out.println(j);
                }
    //test Distin 
    public static int test1(int a , int [] tab, int z ) {
        int t=1;
         
        for(int i=0;i<z;i++){
            if(a==tab[i]){
            
            t= 0;
        }}
        return t ;
    }
            }
