#include <bits/stdc++.h>
using namespace std;
int main() {
  int 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 >= cnt1 &&
          mid - mid / x / y >= cnt1 + cnt2)
        high = mid;
      else
        low = mid + 1;
    }
  }
  cout << low;
}
