#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long cnt1, cnt2, x, y;
  cin >> cnt1 >> cnt2 >> x >> y;
  long long b = 0, e = 10000000000000000ll, s;
  long long fi, se, bo;
  while (e - b > 1) {
    s = (e + b) / 2;
    fi = s / x;
    se = s / y;
    bo = s / (x * y);
    if (x == y) bo = s / x;
    fi -= bo;
    se -= bo;
    if (max(0ll, (cnt1 - se)) + max(0ll, (cnt2 - fi)) <= (s - bo - fi - se))
      e = s;
    else
      b = s;
  }
  cout << e << endl;
  return 0;
}
