import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Comparator;

public class d {
    static BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
    public static void main(String[] args) throws IOException {
       String[] s1=s();
       long cnt1=l(s1[0]);long cnt2=l(s1[1]);long x=l(s1[2]);long y=l(s1[3]);
       long low=1;long high=1000000000000000000L;long ans=0;
       while(low<=high){
           long mid=(low+high)/2;
           long fory=mid/x;
           long forx=mid/y;
           long notforboth=mid/(x*y);
           fory-=notforboth;forx-=notforboth;
           long rem=(mid-(forx+fory-notforboth))
                   ;
            forx+=Math.min(rem,cnt1-forx);
            rem-=Math.min(rem,cnt1-forx);
            fory+=Math.min(rem,cnt2-fory);
            if(forx>=cnt1&&fory>=cnt2){
              ans=mid;
              high=mid-1;
            }else low=mid+1;
       }
        System.out.println(ans);

    }static long val=0;
    static long dfs(ArrayList<Integer>[] adj,int[] vis,int first,int second,int i,StringBuilder sb,long[][] colors,long x){
        vis[i]=1;int color=0;
       // System.out.println(i);
        if(adj[i].size()==3) return -1;
        if(first+second==1){
            val+=colors[2][i-1];color=2;vis[i]=color+1;

        }else if(first+second==2){
            val+=colors[1][i-1];color=1;vis[i]=color+1;

        }else
        { val+=colors[0][i-1];sb.append(1+" ");color=0;vis[i]=color+1;}
        //System.out.println(color+" "+i);
        for(Integer J:adj[i]){
            if(vis[J]==0){
                dfs(adj,vis,second,color,J,sb,colors,val);
            }
        }return 0;
    }
    static String[] s() throws IOException {
        return s.readLine().trim().split("\\s+");
    }
    static int i(String ss) {
        return Integer.parseInt(ss);
    }
    static long l(String ss) {
        return Long.parseLong(ss);
    }
    static int MAXN;
    static int[] spf;
    static void sieve() {
        spf[1] = 1;
        for (int i=2; i<MAXN; i++)
            spf[i] = i;
        for (int i=4; i<MAXN; i+=2)
            spf[i] = 2;
        for (int i=3; i*i<MAXN; i++)
        {
            if (spf[i] == i)
            {
                for (int j=i*i; j<MAXN; j+=i)

                    if (spf[j]==j)
                        spf[j] = i;
            }
        }
    }
    static long powerwithmod(long  x, long y, long p) {
        long  res = 1;
        x = x % p;
        while (y > 0) {
            if ((y & 1) == 1)
                res = (res * x) % p;
            y = y >> 1;
            x = (x * x) % p;
        }
        return res;
    }static long[] fac ;
    static void calculatefac(long mod){
        fac[0]=1;
        for (int i = 1 ;i <= MAXN; i++)
            fac[i] = fac[i-1] * i % mod;
    }
    static long nCrModPFermat(int n, int r, long mod) {
        if (r == 0)
            return 1;
        fac[0] = 1;
        return (fac[n]*
                modInverse(fac[r], mod)
                % mod * modInverse(fac[n-r], mod)
                % mod) % mod;
    }static long modInverse(long a, long m)
    {
        return (powerwithmod(a, m - 2, m));
    }





}

class Student12 {
    int  l;long r;int ind;
    public Student12(int l, long r,int ind) {
        this.l = l;this.ind=ind;
        this.r = r;
    }

    public String toString()
    {
        return this.l+" ";
    }
}
class Sortbyroll12 implements Comparator<Student12> {

    public int compare(Student12 a, Student12 b){
        if(a.l<=b.l) return -1;
     /*   else if(a.r==b.r){
            if(a.r==b.r){
                return 0;
            }
            if(a.r<b.r) return -1;
            return 1;}*/
        return 1;  }
}