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