import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main
{
    public static void main(String[] args) {
        new Thread(null, new Runnable() {
            public void run() {
                solve();
            }
        }, "1", 1 << 26).start();
    }
    static void solve () {
        FastReader fr =new FastReader();    PrintWriter op =new PrintWriter(System.out);
        
        long c1 =fr.nextLong() ,c2 =fr.nextLong() ,x =fr.nextLong() ,y =fr.nextLong() ,i ;
        i =Math.min (calc (c1 , c2 , x , y) , calc (c2 , c1 , y , x)) ;
        op.println(i) ;    op.flush();    op.close();
    }
    static long calc (long c1 , long c2 , long x , long y) {
        long i ,j ,k ;
        k =c1 / (x-1l) ;    if (c1%(x-1l) == 0l)    --k ;    i =k*x ;    c1 -= k*(x-1l) ;
    
        i += c1 ;   c1 =0 ;

        c2 -= (k/y)*(y-1l) ;    c2 -= k%y ;
        if (c2 > 0) {
            k =(i/y + 1) * y ;    k =Math.min(c2 , k-i-1) ;   c2 -= k ;   i += k ;
            if (c2 > 0) {
                ++i ;   k =c2 / (y-1l) ;    if (c2%(y-1l) == 0l)    --k ;
                i += (k*y) ;    c2 -= k*(y-1l) ;    i += c2 ;   c2 =0 ;
            }
        }
        return i ;
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br =new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st==null || (!st.hasMoreElements())) 
            {
                try
                {
                    st =new StringTokenizer(br.readLine());
                }
                catch(IOException e)
                {
                    e.printStackTrace();
                }
                
            }
            return st.nextToken();
        }

        String nextLine() {
            String str ="";

            try
            {
                str =br.readLine();
            }
            catch(IOException e)
            {
                e.printStackTrace();
            }

            return str;
        }

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

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