#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const int IINF = 1000000000;
const double PI = acos(-1.0);
const long long LINF = 6000000000000000000LL;
long long gcd(long long a, long long b) { return a == 0 ? b : gcd(b % a, a); }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
bool can(long long cnt1, long long cnt2, long long x, long long y,
         long long v) {
  long long f = v / (x * y);
  long long c1 = v / x - f;
  long long c2 = v / y - f;
  long long left = v - f;
  if (left - c1 < cnt1) {
    return false;
  }
  if (left - c2 < cnt2) {
    return false;
  }
  cnt1 -= c2;
  cnt2 -= c1;
  left -= c1 + c2;
  return cnt1 + cnt2 <= left;
}
int main() {
  long long cnt1, cnt2, x, y;
  cin >> cnt1 >> cnt2 >> x >> y;
  long long answer = 1e15;
  long long lo = 0, hi = 1e15;
  while (lo <= hi) {
    long long mid = (lo + hi) / 2;
    if (can(cnt1, cnt2, x, y, mid)) {
      answer = min(answer, mid);
      hi = mid - 1;
    } else {
      lo = mid + 1;
    }
  }
  cout << answer << endl;
  return 0;
}
