#include <bits/stdc++.h>
using namespace std;
long long int bin(long long int x, long long int y, long long int c1,
                  long long int c2) {
  long long int mid, l, r, ans;
  l = 1;
  r = 10e9;
  while (l <= r) {
    mid = (l + r) / 2;
    if ((mid - mid / x - mid / y + mid / (x * y)) ==
        (max((c1 - mid / y), 0LL) + max((c2 - mid / x), 0LL))) {
      l = mid + 1;
      ans = mid;
    } else if ((mid - mid / x - mid / y + mid / (x * y)) >
               ((c1 - mid / y) + (c2 - mid / x)))
      r = mid - 1;
    else
      l = mid + 1;
  }
  return ans;
}
int main() {
  long long int c1, c2, x, y;
  cin >> c1 >> c2 >> x >> y;
  cout << bin(x, y, c1, c2) << endl;
  return 0;
}
