#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int cnt[2], v[2];
bool f(ll val) {
  ll f[] = {val / v[0], val / v[1]};
  ll b = v[0] * 1ll * v[1];
  ll both = val / b;
  ll other = val - f[0] - f[1] + both;
  f[0] -= both;
  f[1] -= both;
  ll tcnt[] = {cnt[0] - f[1], cnt[1] - f[0]};
  if (tcnt[0] < 0) tcnt[0] = 0;
  if (tcnt[1] < 0) tcnt[1] = 0;
  return (tcnt[0] + tcnt[1] <= other);
}
int main() {
  cin >> cnt[0] >> cnt[1] >> v[0] >> v[1];
  ll l = 0;
  ll r = ll(1e18);
  while (r - l > 1) {
    ll mid = (l + r) >> 1;
    if (f(mid)) {
      r = mid;
    } else {
      l = mid;
    }
  }
  cout << r << endl;
}
