#include <bits/stdc++.h>
using namespace std;
long long MAX = 1e18;
long long cn1, cn2, x, y;
int main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  cin >> cn1 >> cn2 >> x >> y;
  long long in, fn, m, t1, t2;
  in = 2;
  fn = MAX;
  while (in != fn) {
    m = (in + fn) / 2;
    t1 = max(cn1 - (m / y) + (m / (x * y)), 0LL);
    t2 = max(cn2 - (m / x) + (m / (x * y)), 0LL);
    if ((m - ((m / y) - (m / (x * y)) + (m / x))) >= (t1 + t2)) {
      fn = m;
    } else {
      in = m + 1;
    }
  }
  cout << in << endl;
}
