#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long f1, f2, p1, p2;
  cin >> f1 >> f2 >> p1 >> p2;
  long long lo = f1 + f2, hi = 2 * lo;
  while (lo < hi) {
    long long mid = (lo + hi) >> 1;
    if (f1 + f2 <= mid - mid / (p1 * p2) && f1 <= (mid - mid / p1) &&
        f2 <= (mid - mid / p2))
      hi = mid;
    else
      lo = mid + 1;
  }
  cout << lo;
}
