#include <bits/stdc++.h>
using namespace std;
long long c1, c2, x, y;
long long check(long long mid) {
  long long t1 = mid - mid / x, t2 = mid - mid / y;
  if (t1 >= c1 && t2 >= c2 && c1 + c2 <= mid) return true;
  return false;
}
int main() {
  scanf("%lld%lld%lld%lld", &c1, &c2, &x, &y);
  long long l = 0, r = 1e10, ans;
  while (l <= r) {
    long long mid = l + r >> 1;
    if (check(mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  cout << ans << endl;
}
