import java.io.*;
import java.util.*;

public class Main {
    /**
     * author geshpaniec
     * 23.10.2014
     */

    StringTokenizer in;
    BufferedReader inb;
    PrintWriter out;
    static boolean local;
    final String problemname = "success";
    final static String _localArg="geshpaniec";
    final static byte IO=1;
        /* IO:
         * 1 - standard I/O
         * 2 - input.txt/output.txt
         * 3 - problemname.in/problemname.out
         */

    public void solve() throws Exception {
        int cnt1=nextInt(),cnt2=nextInt(),x=nextInt(),y=nextInt();
        if (cnt1==1&&cnt2==1){
            if (x==2||y==2){
                if (x==3||y==3){
                    out.println(5);
                    return;
                }
                else{
                    out.println(3);
                    return;
                }
            }
            else {
                out.println(2);
                return;
            }
        }
        int l=0,count=0;
        for (int i=y;;i+=y){
            if (i%x==0)
                l++;
            if (cnt1+cnt2-(i/y+i/x-2*l)<=i-i/y-i/x+l) {
                count = i;
                break;
            }
        }
        for (;;count--){
            int w1=(cnt1-count/y+l)>0?(cnt1-count/y+l):0;
            int w2=(cnt2-count/x+l)>0?(cnt2-count/x+l):0;
            if (w1+w2>count-count/y-count/x+l) {
                out.println(count+1);
                break;
            }
            if (count%x==0&&count%y==0)
                l--;
        }
    }


    long NOD (long a, long b) {
        return b!=0 ? NOD (b, a % b) : a;
    }

    public static void main(String[] args) throws Exception {
        local = false;
        if (args.length == 1 && args[0].equals(_localArg))
            local = true;
        new Main().run();

    }

    public void run() throws Exception {
        if (local) {
            inb = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter(new OutputStreamWriter(System.out));
        } else {
            switch (IO){
                case 1:
                    inb = new BufferedReader(new InputStreamReader(System.in));
                    out = new PrintWriter(new OutputStreamWriter(System.out));
                    break;
                case 2:
                    inb = new BufferedReader(new FileReader("input.txt"));
                    out = new PrintWriter(new FileWriter("output.txt"));
                    break;
                case 3:
                    inb = new BufferedReader(new FileReader(problemname+".in"));
                    out = new PrintWriter(new FileWriter(problemname+".out"));
                    break;
            }
        }
        in = new StringTokenizer("");
        double Time=System.nanoTime();
        solve();
        if (local){
            Time=System.nanoTime()-Time;
            out.println();
            out.println(" Time work: "+Time/(1e9)+" seconds");
        }
        out.flush();
    }

    int nextInt() throws Exception {
        return Integer.parseInt(next());
    }

    long nextLong() throws Exception{
        return Long.parseLong(next());
    }

    double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }

    String next() throws Exception {
        if (!in.hasMoreTokens())
            in=new StringTokenizer(inb.readLine());
        return in.nextToken();
    }

    int[] nextArray(int n) throws Exception{
        int[] a=new int[n];
        for (int i=0;i<n;i++)
            a[i]=nextInt();
        return a;
    }

    long[] nextLArray(int n) throws Exception{
        long[] a=new long[n];
        for (int i=0;i<n;i++)
            a[i]=nextLong();
        return a;
    }

    double[] nextDArray(int n) throws Exception{
        double[] a=new double[n];
        for (int i=0;i<n;i++)
            a[i]=nextDouble();
        return a;
    }

    String[] nextSArray(int n) throws Exception{
        String[] a=new String[n];
        for (int i=0;i<n;i++)
            a[i]=next();
        return a;
    }

    void print(int[] a){
        for (int i=0;i<a.length;i++)
            out.println(a[i]);
    }

    void print(double[] a){
        for (int i=0;i<a.length;i++)
            out.println(a[i]);
    }

}