#include <bits/stdc++.h>
using namespace std;
long long maxN(long long a, long long b) {
  if (a > b) return a;
  return b;
}
bool enough(long long i, long long x, long long c1, long long y, long long c2) {
  long long Ax = i - (i / x);
  long long Ay = i - (i / y);
  long long over = (i / (x * y));
  Ax -= i / (x * y);
  Ay -= i / (x * y);
  c1 = maxN(c1 - Ax, 0);
  c2 = maxN(c2 - Ay, 0);
  if (c1 + c2 <= over) return 1;
  return 0;
}
int main() {
  long long c1, c2, x, y;
  cin >> c1 >> c2 >> x >> y;
  long long on = 4294967296;
  long long interval = 4294967296 / 2;
  while (interval > 0) {
    if (enough(on, x, c1, y, c2)) {
      on -= interval;
      interval /= 2;
    } else {
      on += interval;
      interval /= 2;
    }
  }
  if (enough(on, x, c1, y, c2))
    cout << on << endl;
  else
    cout << on + 1 << endl;
  return 0;
}
