#include <bits/stdc++.h>
using namespace std;
long long int c1, c2, x, y, l, r, mid;
int main() {
  ios::sync_with_stdio(false);
  cin >> c1 >> c2 >> x >> y;
  l = c1 + c2;
  r = 2000000009;
  while (l < r) {
    mid = (l + r) / 2;
    if ((mid - (mid / x) >= c1) && (mid - (mid / y) >= c2) &&
        (mid - (mid / (x * y)) >= (c1 + c2)))
      r = mid;
    else
      l = mid + 1;
  }
  cout << l << endl;
  return 0;
}
