#include <bits/stdc++.h>
using namespace std;
int x, y, a, b;
bool can(long long c) {
  long long nf = c / a, ns = c / b;
  long long resa = max(x - ns, 0LL), resb = max(y - nf, 0LL);
  long long b = c - nf - ns;
  if (resa + resb <= b) return 1;
  return 0;
}
int main() {
  cin >> x >> y >> a >> b;
  long long st = 1, en = (1LL << 50), ans = (1LL << 50);
  while (st <= en) {
    long long mid = (st + en) / 2;
    if (can(mid)) {
      ans = mid;
      en = mid - 1;
    } else
      st = mid + 1;
  }
  cout << ans << endl;
}
