#include <bits/stdc++.h>
using namespace std;
long long cnt1, cnt2, x, y;
bool ifpossible(long long n) {
  long long rest =
      (long long)(n / x) + (long long)(n / y) - (long long)(n / (x * y));
  rest = n - rest;
  rest -= ((cnt1 - (long long)(n / y) + (long long)(n / (x * y))) > 0
               ? (cnt1 - (long long)(n / y) + (long long)(n / (x * y)))
               : 0);
  rest -= ((cnt2 - (long long)(n / x) + (long long)(n / (x * y))) > 0
               ? (cnt2 - (long long)(n / x) + (long long)(n / (x * y)))
               : 0);
  return rest >= 0;
}
int main() {
  long long hi = 2 * pow(10, 9), lo = 0, mid, ans;
  cin >> cnt1 >> cnt2 >> x >> y;
  while (hi >= lo) {
    mid = (hi + lo) / 2;
    if (ifpossible(mid)) {
      hi = mid - 1;
      ans = mid;
    } else
      lo = mid + 1;
  }
  cout << ans;
  return 0;
}
