#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, x, y;
  cin >> a >> b >> x >> y;
  long long t = a + b;
  long long i = 0, j = 0, k = 0;
  long long q = a, p = b;
  while (a != 0 || b != 0) {
    i = t / x;
    j = t / y;
    k = t - (i + j + t / (x * y));
    if (a - j > 0)
      a -= j;
    else
      a = 0;
    if (b - i > 0)
      b -= i;
    else
      b = 0;
    if (a + b - k == 0) break;
    t += a + b - k;
    a = q;
    b = p;
  }
  cout << t;
  return 0;
}
