#include <bits/stdc++.h>
using namespace std;
string line = "\n";
long long c1, c2, x, y;
bool canPresent(long long v) {
  long long both = v / (x * y);
  long long like1 = v - v / x;
  long long like2 = v - v / y;
  long long good = like1 + like2 - both;
  if (good < c1 + c2 || like1 < c1 || like2 < c2) {
    return false;
  }
  long long rem1 = c1 - (like1 - both);
  long long rem2 = c2 - (like2 - both);
  if (rem1 + rem2 > both) {
    return false;
  }
  return true;
}
int main() {
  cin.tie(NULL), ios_base::sync_with_stdio(0);
  cin >> c1 >> c2 >> x >> y;
  long long low = 0;
  long long high = 1e18;
  while (high > low + 1) {
    long long mid = (high + low) / 2;
    if (canPresent(mid)) {
      high = mid;
    } else {
      low = mid;
    }
  }
  cout << high << line;
  return 0;
}
