#include <bits/stdc++.h>
using namespace std;
long long int c1, c2, x, y, s, m, e = 1e10, sol;
int main() {
  cin >> c1 >> c2 >> x >> y;
  while (s <= e) {
    m = (s + e) / 2;
    if (c1 + c2 + (c1 < m / y ? 0 : m / y) - (c2 < m / x ? 0 : m / x) +
            m / (x * y) <=
        m) {
      sol = m;
      e = m - 1;
    } else {
      s = m + 1;
    }
  }
  cout << sol << endl;
}
