import java.util.Scanner;

public class Friends_and_Presents {

    
    public static boolean valid (int v,int cnt1,int cnt2,int x,int y){
        // for example v=6
        int notDByX = v-v/x; //{1,3,5}
        int notDByY = v-v/y; //{1,2,4,5}
        int notDByXxY = v-v/(x*y);//{1,2,3,4,5}
        int notDByXnorY = notDByX+notDByY-notDByXxY;//{1,5}/**/
        int DbyXonlx = notDByX-notDByXnorY;//{3}           /**/
        int DbyYonly = notDByY-notDByXnorY;//{2,4}         /**/
        if (DbyXonlx<cnt1){
            int dx = cnt1-DbyXonlx;
            if (dx>notDByXnorY) return false;
            else notDByXnorY-=dx;
        }
        if (DbyYonly<cnt2) {
            int dy = cnt2-DbyYonly;
            if (dy>notDByXnorY) return false;
        }
        return true;
    }
    
    public static void main(String[] args) {
        Scanner s = new Scanner (System.in);
        int cnt1, cnt2, x, y,c1=0,c2=0;
        cnt1=s.nextInt();
        cnt2=s.nextInt();
        x=s.nextInt();
        y=s.nextInt();
        int lo=cnt1+cnt2;
        int hi=(int)10e8;
        int mid,max=0;
        while (hi-lo>1){
            mid = lo + (hi-lo)/2;
            if (valid(mid,cnt1,cnt2,x,y)){
                max=mid;
                hi=mid;
            }
            else lo = mid+1;
        }
        if (valid(lo,cnt1,cnt2,x,y)) max=lo;
        System.out.print(max);
    }
}