#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-10;
const long long INF = (long long)(1e18);
const int mod = (int)(1e+9 + 7);
const int N = (int)(5e5);
int days_month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int cnt1, cnt2, x, y;
inline bool can(long long lim) {
  long long mx = lim / x;
  long long my = lim / y;
  long long mb = lim / (x * y);
  long long tot = lim - mx - my + mb;
  long long cnt1_ = max(0LL, cnt1 - (my - mb));
  long long cnt2_ = max(0LL, cnt2 - (mx - mb));
  return cnt1_ + cnt2_ <= tot;
}
int bs() {
  long long l = 0;
  long long r = INF;
  while (l <= r) {
    long long me =
        ((((l + r)) / ((2)) - (((l + r)) < 0 && ((l + r)) % ((2)) != 0)) +
         ((l + r) % (2) > 0));
    if (can(me))
      r = me - 1;
    else
      l = me + 1;
  }
  return l;
}
int main() {
  cin >> cnt1 >> cnt2 >> x >> y;
  cout << bs();
  return 0;
}
