#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  ios_base::sync_with_stdio(true);
  int c1, c2, a, b;
  cin >> c1 >> c2 >> a >> b;
  long long lo, hi, mid, numdiva, numdivb, numdivl, lcm, gc, na, nb, nl;
  lo = 0;
  hi = 3 * (1e9);
  gc = gcd(a, b);
  lcm = a;
  lcm = (lcm * b) / gc;
  while (hi > lo) {
    mid = (lo + hi) >> 1;
    numdiva = mid / a;
    na = mid - numdiva;
    if (na < c1) {
      lo = mid + 1;
      continue;
    }
    numdivb = mid / b;
    nb = mid - numdivb;
    if (nb < c2) {
      lo = mid + 1;
      continue;
    }
    numdivl = mid / lcm;
    nl = mid - (numdiva + numdivb - numdivl);
    if (na + nb - nl >= (c1 + c2))
      hi = mid;
    else
      lo = mid + 1;
  }
  cout << lo << "\n";
  return 0;
}
