#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
const int mod = 1e9 + 7;
int dcmp(long double x, long double y) {
  return fabs(x - y) <= 1e-12 ? 0 : x < y ? -1 : 1;
}
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
long long n, m, x, y;
bool ok(long long md) {
  long long divisiblebyx = md / x, divisiblebyy = md / y,
            divisblebyboth = md / x / y;
  divisiblebyx -= divisblebyboth;
  divisiblebyy -= divisblebyboth;
  long long notdivisibleatall =
      (md - divisiblebyx - divisiblebyy - divisblebyboth);
  long long tmpn = n, tmpm = m;
  tmpn -= divisiblebyy;
  tmpm -= divisiblebyx;
  tmpn = max(0ll, tmpn);
  tmpm = max(0ll, tmpm);
  return (tmpn + tmpm <= notdivisibleatall);
}
int main() {
  fast();
  cin >> n >> m >> x >> y;
  long long lo = 1, hi = 1e9, ans = 1e15 + 1;
  while (lo <= hi) {
    long long md = lo + (hi - lo) / 2;
    if (ok(md)) {
      hi = md - 1;
      ans = min(ans, md);
    } else
      lo = md + 1;
  }
  cout << ans << '\n';
  return 0;
}
