#include <iostream>
#include <vector>
#include <cmath>
#define int long long

using namespace std;

int c1, c2, x, y;
int R = 10e17, L = -1;

int ev(int x, int y) {
    if (x == 0) return y;
    if (y == 0) return x;
    return ev(y % x, x);
}

bool check(int a) {
    int ans1 = a - a / x - a / y + a / ((x + y) / ev(x, y));
    int nc1 = a / y - a / ((x + y) / ev(x, y));
    int nc2 = a / x - a / ((x + y) / ev(x, y));
    //cout << ans1 << ' ' << nc1 << ' ' << nc2 << endl;
    return ans1 >= (c1 - nc1) + (c2 - nc2);
}

main() {
    cin >> c1 >> c2 >> x >> y;
    while (R - L > 1) {
        int M = (R + L) / 2;
        if (check(M)) {
            R = M;
        }
        else {
            L = M;
        }
    }
    cout << R;
}
