import java.util.*;
public class Sport {

    public static void main(String[] args) 
    {
        
        Scanner sc = new Scanner(System.in);
        long cnt1 = 0,cnt2=0,v = 1;
        int x=2,y=2,t = 0,k=0;
        cnt1=sc.nextLong();
        cnt2=sc.nextLong();
        x=sc.nextInt();
        y=sc.nextInt();
       
        while (t!=x && k!=y)
        {if(cnt1%x!=0){v++;t++;}if (t==x){t=t;} 
        if(cnt1%x==0 && cnt2%y!=0){v++;k++;}if (k==y){k=k;}
        }
        if (v<=cnt1+cnt2){v++;}
        System.out.print(v);
       
        
    }
        
    }