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


public class B {
    BufferedReader br;
    StringTokenizer in;
    PrintWriter out;
    
    public String nextToken() throws IOException {
        while (in == null || !in.hasMoreTokens()) {
            in = new StringTokenizer(br.readLine());
        }

        return in.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
    
    public void solve() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        
        long c1 = nextLong();
        long c2 = nextLong();
        long x = nextLong();
        long y = nextLong();
        
        long lower = 1;
        long upper = 1000000000;
        long answer = upper;

        while(lower <= upper) {
            long middle = lower + upper;
            middle = middle / 2;
            
            if(check(c1,c2,x,y,middle)) {
                answer = middle;
                upper = middle - 1;
            }else {
                lower = middle + 1; 
            }
        }
 //      for(long i = answer ; i>= answer - 100 ; i--)
  //       if(check(c1,c2,x,y,i))
   //          answer = i;
        out.println(answer);
        out.close();
    }
    
    public static boolean check(long c1, long c2, long x, long y, long v) {
        long count1 = v - (v/x) ;
        long count2 = v - (v/y) ;
        long count3 = (v/(x*y));
        long common = Math.min(x, y) - 1;
        count1 -= common;
        count2 -= common;
        count3 = common;
        long diff1 = c1 - count1;
        long diff2 = c2 - count2;
        
        if(diff1 >= 0 && diff2 >= 0) {
            return (count3) >= diff1 + diff2;
        }
        if(diff1 >= 0)
            return count3 >= diff1;
        if(diff2 >= 0)
            return count3 >= diff2;
        return true;
    }
    
    public static void main (String [] args) throws IOException {
        new B().solve();
    }
}
