#include <bits/stdc++.h>
using namespace std;
long long cnt1, cnt2, x, y;
bool check(long long m) {
  long long gong = m / (x * y);
  long long x1 = m / x - gong;
  long long y1 = m / y - gong;
  long long sum = m - x1 - y1 - gong;
  if ((m - gong) >= (cnt1 + cnt2) && (sum + x1) >= cnt2 && (sum + y1) >= cnt1)
    return true;
  else
    return false;
}
int main() {
  scanf("%lld%lld%lld%lld", &cnt1, &cnt2, &x, &y);
  long long l = max(cnt1, cnt2) - 1;
  long long r = 5000000000000000000;
  while ((l + 1) < r) {
    long long mid = l + (r - l) / 2;
    if (check(mid))
      r = mid;
    else
      l = mid;
  }
  printf("%lld\n", r);
  return 0;
}
