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)
        {
            int cur=(max-min)/2 + min;
            if(check(cur,cnt1,cnt2,x,y))max=cur;
            else min=cur+1;
            
        }
        System.out.print(min);
        
    }
    static boolean check(int cur,int c1,int c2,int x,int y)
    {
        boolean ok=false;
        
        if(cur-(cur/x) >= c1 && cur-(cur/y) >= c2)
            ok=true;
        return ok;
        
    }

}
