#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d;
bool check(long long m) {
  long long cantA = m / c;
  long long cantB = m / d;
  long long cantNeither = m / (c * d);
  long long canA = m - cantA;
  long long canB = m - cantB;
  long long canBoth = m - cantA - cantB + cantNeither;
  if (canA < a) return false;
  if (canB < b) return false;
  if (canA + canB - canBoth < (a + b)) return false;
  return true;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin >> a >> b >> c >> d;
  long long l = 1, r = 2000000000000;
  long long ans = (1ll << 60);
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (check(mid)) {
      ans = min(ans, mid);
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  cout << ans << "\n";
}
