#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int c, long long int d) {
  if (d == 0)
    return c;
  else
    return gcd(d, c % d);
}
long long int cnt1, cnt2, x, y;
int main() {
  cin >> cnt1 >> cnt2 >> x >> y;
  long long int l = 0, h = 100000000000000000, mid;
  while (l <= h) {
    mid = (l + h) / 2;
    long long int p, q, r;
    p = mid / x;
    p = mid - p;
    q = mid / y;
    q = mid - q;
    r = mid / (x * y);
    r = mid - r;
    if (p >= cnt1 && q >= cnt2 && r >= (cnt1 + cnt2)) {
      h = mid - 1;
    } else
      l = mid + 1;
  }
  cout << mid << endl;
  return 0;
}
