#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int cnt1, cnt2, x, y;
  cin >> cnt1 >> cnt2 >> x >> y;
  long long int lo = 0, hi = 1e18, mid;
  while (lo < hi) {
    mid = (lo + hi) / 2;
    long long int _x = mid / x;
    long long int _y = mid / y;
    long long int _xy = mid / (x * y);
    long long int xCanTake = _y - _xy;
    long long int yCanTake = _x - _xy;
    long long int bothCanTake = mid - xCanTake - yCanTake + _xy;
    long long int xLeft = max(0ll, cnt1 - xCanTake);
    long long int yLeft = max(0ll, cnt2 - yCanTake);
    if (xLeft + yLeft <= bothCanTake)
      hi = mid;
    else
      lo = mid + 1;
  }
  cout << hi << endl;
  return 0;
}
