#include <bits/stdc++.h>
using namespace std;
long long c1, c2, x, y;
bool ok(long long mid) {
  long long vx = mid / x;
  long long vy = mid / y;
  long long both = mid / (x * y);
  long long vb = mid - (vx + vy) + both;
  return max(0ll, (c1 - (vy - both))) + max(0ll, (c2 - (vx - both))) <= vb;
}
int main(void) {
  cin >> c1 >> c2 >> x >> y;
  long long st = (c1 + c2), en = 20, ans = st;
  while (st <= en) {
    long long mid = (st + en) / 2;
    if (ok(mid)) {
      ans = mid;
      en = mid - 1;
    } else
      st = mid + 1;
  }
  cout << ans << endl;
  return 0;
}
