#include <bits/stdc++.h>
using namespace std;
int cnt[2], v[2];
bool Solve(long long x) {
  long long f[] = {x / v[0], x / v[1]};
  long long l = 1ll * v[0] * v[1];
  long long both = x / l;
  long long other = x - f[0] - f[1] + both;
  f[0] -= both;
  f[1] -= both;
  long long 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.sync_with_stdio(false);
  cin >> cnt[0] >> cnt[1] >> v[0] >> v[1];
  long long l = 0, r = 5;
  while (r - l > 1) {
    long long m = (l + r) >> 1;
    if (Solve(m))
      r = m;
    else
      l = m;
  }
  cout << r;
  return 0;
}
