#include <bits/stdc++.h>
using namespace std;
struct _ {
  ios_base::Init i;
  _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); }
} _;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
const int MOD = 1e9 + 7;
class MainClass {
 public:
  void solve() {
    int cnt1, cnt2, x, y;
    cin >> cnt1 >> cnt2 >> x >> y;
    auto check = [&](int v) {
      int xym = v / (x * y);
      int tot = v - xym;
      int only_xm = v / x - xym;
      if (cnt1 > tot - only_xm) return false;
      tot -= cnt1;
      return tot >= cnt2;
    };
    int lo = 1, hi = 2e9, ans = -1;
    while (lo <= hi) {
      int mid = lo + (hi - lo) / 2;
      if (check(mid))
        ans = mid, hi = mid - 1;
      else
        lo = mid + 1;
    }
    cout << ans;
    return;
  }
};
int main() {
  int test = 1;
  for (int tst = 1; tst <= test; ++tst) {
    MainClass Ausmosian;
    Ausmosian.solve();
    cout << "\n";
  }
  return 0;
}
