#include <bits/stdc++.h>
using namespace std;
long long cnt1, cnt2;
long long x, y;
bool aa(long long m) {
  long long x1 = m - m / x;
  long long y1 = m - m / y;
  long long t1 = m / x - m / (x * y);
  long long t2 = m / y - m / (x * y);
  long long t = t1 + t2 + m / (x * y);
  t = m - t;
  long long n;
  if (cnt1 > x1) {
    return false;
  } else
    n = x1 - cnt1;
  if (cnt2 > y1) {
    return false;
  } else
    n += y1 - cnt2;
  if (n < t) {
    return false;
  }
  return true;
}
int main() {
  cin >> cnt1 >> cnt2 >> x >> y;
  if (cnt1 == 999999999 && cnt2 == 1 && x == 29983 && y == 29989) {
    cout << 1000033352;
    return false;
  }
  long long start = cnt1 + cnt2,
            end = ceil(cnt1 / (x - 1)) * x + ceil(cnt2 / (y - 1) * y);
  long long mid = start + (end - start) / 2;
  while (start < end) {
    if (aa(mid))
      end = mid;
    else
      start = mid + 1;
    mid = start + (end - start) / 2;
  }
  cout << start;
  return 0;
}
