#include <bits/stdc++.h>
using namespace std;
long long cnt1, cnt2;
int x, y;
bool binarysearch(long long val) {
  long long both = val / (x * y);
  long long pre1 = cnt1 - val / y + both;
  long long pre2 = cnt2 - val / x + both;
  long long other = val - val / x - val / y + both;
  if (pre1 < 0) pre1 = 0;
  if (pre2 < 0) pre2 = 0;
  return (pre1 + pre2 <= other);
}
int main() {
  while (cin >> cnt1 >> cnt2) {
    cin >> x >> y;
    long long l = 0;
    long long r = 1000000001;
    while (r - l > 1) {
      long long mid = (l + r) >> 1;
      if (binarysearch(mid))
        r = mid;
      else
        l = mid;
    }
    cout << r << endl;
  }
  return 0;
}
