import java.util.*;
public class B {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int cnt1= sc.nextInt(),cnt2=sc.nextInt(),x=sc.nextInt(),y=sc.nextInt(),min=0,max=1000000000;
        while(min < max)
        {
            
               
                
                    if(max==(min+1))
                    {
                        if(check(min,cnt1,cnt2,x,y))
                        {
                            System.out.print(min);return;
                        }
                        System.out.print(max);
                        return;
                    }
                    int mid=(min+max)>>1;
                    if(check(mid,cnt1,cnt2,x,y))
                    {
                        max=mid;
                    }
                    else
                    {
                        min=mid+1;
                    }
                }
            
         
        System.out.print(min);
        
    }
    static boolean check(int cur,int c1,int c2,int x,int y)
    {
        boolean ok=false;
        int n1=(cur/x),n2=(cur/y),n3=(cur/(x*y));
        n1-=n3;n2-=n3;
         int cnt1=c2-n1;
         int cnt2=c1-n2;
         int remain=cur-n1-n2-n3;
            cnt1=Math.max(cnt1,0);
            cnt2=Math.max(cnt2, 0);
            
            if(cnt1+cnt2<=remain)
            {
                return true;
            }
        return ok;
        
    }

}
