#include <bits/stdc++.h>
using namespace std;
int main() {
  long long cnt1, cnt2, x, y;
  cin >> cnt1 >> cnt2 >> x >> y;
  long long low = 1, high = 4000000000LL;
  if (x == y) {
    while (low < high) {
      long long mid = low + (high - low) / 2;
      if (mid - mid / x >= cnt1 + cnt2)
        high = mid;
      else
        low = mid + 1;
    }
  } else {
    while (low < high) {
      long long mid = low + (high - low) / 2;
      if (mid - mid / x >= cnt1 && mid - mid / y >= cnt2 &&
          mid - mid / (x * y) >= cnt1 + cnt2)
        high = mid;
      else
        low = mid + 1;
    }
  }
  cout << low;
}
