#include <bits/stdc++.h>
using namespace std;
long long pw(long long b, long long p) {
  if (!p) return 1;
  long long sq = pw(b, p / 2);
  sq *= sq;
  if (p % 2) sq *= b;
  return sq;
}
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }
long long sd(long long x) { return x < 10 ? x : x % 10 + sd(x / 10); }
long long lcm(long long a, long long b) { return ((a * b) / gcd(a, b)); }
long long cnt1, cnt2, x, y, LCM;
long long BS() {
  LCM = x * y;
  long long s = 0, e = 1e18, m, b, ft, rf, st, rs, rem;
  while (s <= e) {
    m = s + (e - s) / 2;
    ft = m / y - m / LCM;
    st = m / x - m / LCM;
    rf = max(0LL, cnt1 - ft);
    rs = max(0LL, cnt2 - st);
    rem = m - ft - st - m / LCM;
    if (rem >= rf + rs) {
      b = m;
      e = m - 1;
    } else
      s = m + 1;
  }
  return b;
}
int main() {
  cin >> cnt1 >> cnt2 >> x >> y;
  printf("%lld\n", BS());
}
