#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000000000000ll;
int main() {
  long long c1, c2, x, y;
  cin >> c1 >> c2 >> x >> y;
  long long lo = 0, hi = INF;
  while (hi - lo > 1) {
    long long mid = (lo + hi) / 2;
    long long v2 = (mid / x) - mid / (x * y);
    long long v1 = (mid / y) - mid / (x * y);
    long long rest = mid - (mid / x) - (mid / y) + (mid / (x * y));
    if (rest >= max(0ll, c1 - v1) + max(0ll, c2 - v2))
      hi = mid;
    else
      lo = mid;
  }
  cout << hi << endl;
}
