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

public class friends_presents
{
	static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
    }
	public static void main(String args[])throws IOException
	{
		InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader sc = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
       
        int cnt1 = sc.nextInt();
        int cnt2 = sc.nextInt();
        
        int x = sc.nextInt();
        int y = sc.nextInt();
        
        long l = 1;
        long r = (long)1e9;
        long mid = 0;
        long ans = 0;
        while (l <= r)
        {
        	mid = (l+r)/2;
        	if (mid - mid/x >= cnt1 && mid - mid/y >= cnt2 && mid - mid/x/y >= cnt1+cnt2)
        	{ans = mid; r = mid-1;}
        	else 
        		l = mid+1;
        }
        out.println(ans);
        
		out.close();
		out.flush();
	}

}
