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