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

import static java.lang.Math.min;

public class Solution_A {
    private static BufferedReader in;
    private static StringTokenizer st;
    private static PrintWriter out;

    private static final boolean IS_JUDGE = true;

    public static void main(String[] args) throws IOException {
        if (IS_JUDGE) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(new OutputStreamWriter(System.out));
        } else {
            in = new BufferedReader(new FileReader(new File("input.txt")));
            out = new PrintWriter(new FileWriter(new File("output.txt")));
        }

        new Solution_A().solve();
        out.close();
    }

    long cnt1;
    long cnt2;

    private void solve() throws IOException {
        cnt1 = nextLong();
        cnt2 = nextLong();

        int x = nextInt();
        int y = nextInt();

        long l = (cnt1 + cnt2);
        long r = (int) (2e9) + 100;

        int cnt = 0;
        while (r - l > 0) {
            ++cnt;

            if (cnt > 1000) {
                break;
            }

            long mid = l + (r - l) / 2;

            if (f(mid, x, y)) {
                r = mid;
            } else {
                l = mid;
            }
        }

        if (f(l, x, y)) {
            out.println(l);
        } else {
            out.println(r);
        }
    }

    private boolean f(long r, int x, int y) {
        long first = r - (r / x);
        long second = r - (r / y);

        return first >= cnt1 && (r - first) >= cnt2 ||
                (r - second) >= cnt1 && second >= cnt2;
    }

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

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

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

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