#include <bits/stdc++.h>
long long gcd(long long a, long long b) {
  if (b > a) std::swap(a, b);
  if (b == 0)
    return a;
  else
    return gcd(a - b, b);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
void countNumbers(long long maxNumber, long long x, long long y,
                  long long& noone, long long& only1, long long& only2,
                  long long& both) {
  long long _lcm = x * y;
  noone = maxNumber / _lcm;
  only1 = maxNumber / y - noone;
  only2 = maxNumber / x - noone;
  both = maxNumber - only1 - only2 - noone;
}
bool isEnough(long long maxNumber, long long cnt1, long long cnt2, long long x,
              long long y) {
  long long noone, only1, only2, both;
  countNumbers(maxNumber, x, y, noone, only1, only2, both);
  return ((only1 + both >= cnt1) && (only1 + only2 + both >= cnt1 + cnt2));
}
long long findMinEnough(long long l, long long r, long long cnt1,
                        long long cnt2, long long x, long long y) {
  if (l == r) return l;
  long long m = (l + r) / 2;
  if (isEnough(m, cnt1, cnt2, x, y)) {
    return findMinEnough(l, m, cnt1, cnt2, x, y);
  } else {
    return findMinEnough(m + 1, r, cnt1, cnt2, x, y);
  }
}
int main() {
  long long cnt1, cnt2, x, y;
  std::cin >> cnt1 >> cnt2 >> x >> y;
  std::cout << findMinEnough(1, 8e9, cnt1, cnt2, x, y);
  return 0;
}
