#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, x, y, l, r, m;
  while (cin >> a >> b >> x >> y) {
    l = 1;
    r = (a + b) << 2;
    while (l <= r) {
      m = (l + r) >> 1;
      if (m - m / x / y >= a + b && m - m / x >= a && m - m / y >= b)
        r = m - 1;
      else
        l = m + 1;
    }
    cout << l << endl;
  }
  return 0;
}
