#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;
  if (m - cantA < a) return false;
  if (m - cantB < 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";
}
