#include <bits/stdc++.h>
using namespace std;
unsigned long long int gcd(unsigned long long int a, unsigned long long int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
unsigned long long int lcm(unsigned long long int a, unsigned long long int b) {
  return a * b / (gcd(a, b));
}
int main() {
  unsigned long long int c1, c2, x, y;
  cin >> c1 >> c2 >> x >> y;
  unsigned long long int l = lcm(x, y);
  unsigned long long int index = (c1 + c2) + (c1 + c2) / l;
  if (index - (index / x) >= c1 && index - (index / y) >= c2) {
    cout << index << endl;
  } else {
    index = max((c1 - 1) * x / (x - 1), (c2 - 1) * y / (y - 1));
    for (unsigned long long int i = index;; i++) {
      if (i % l == 0) {
        i++;
      }
      if (i - (i / x) >= c1 && i - (i / y) >= c2) {
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}
