#include <bits/stdc++.h>
using namespace std;
int main() {
  long long l, r, m, a, b, x, y, v, k;
  cin >> a >> b >> x >> y;
  l = 0;
  r = 1000000000000000000;
  while (l + 1 < r) {
    m = (l + r) / 2;
    k = m - (m / x) - (m / y) + (m / (x * y));
    if (k >= max(0ll, b - (m / x)) + max(0ll, a - (m / y)))
      r = m;
    else
      l = m;
  }
  m = l;
  k = m - (m / x) - (m / y) + (m / (x * y));
  if (k >= max(0ll, b - (m / x)) + max(0ll, a - (m / y))) r = m;
  cout << r;
  return 0;
}
