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

public class B {

    public static void main(String[] args) {
        InputScanner scanner = new InputScanner();
        try {
            int cnt1 = scanner.nextInt();
            int cnt2 = scanner.nextInt();
            int x = scanner.nextInt();
            int y = scanner.nextInt();

            int min = 1;
            int max = 1000000000;
            int ans = 0;
            int result = 0;
            while (min <= max) {
                ans = (max - min) / 2 + min;
                if (check(ans, cnt1, cnt2, x, y)) {
                    result = ans;
                    max = ans - 1;
                } else
                    min = ans + 1;
            }
            System.out.println(result);
        } catch (IOException e) {

        }


    }

    public static boolean check(int number, int cnt1, int cnt2, int x, int y) {
        int divBoth = number / (x * y);
        int first = Math.min(cnt1, number / y - divBoth);
        int second = Math.min(cnt2, number / x - divBoth);
        int both = number - number / y - number / x + divBoth;
        if (first + second + both >= cnt1 + cnt2) return true;
        return false;
    }

    static class InputScanner {

        BufferedReader br;
        StringTokenizer st;

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

        public String next() throws IOException {
            if (st == null || !st.hasMoreTokens()) {
                String line = br.readLine();
                st = new StringTokenizer(line);
            }
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            String next = next();
            next.length();
            return Integer.parseInt(next);
        }
    }
}