#include <bits/stdc++.h>
using namespace std;
long long a, b, x, y, javab = (long long)1000 * 1000 * 1000 * 1000;
bool chek(long long m, long long s1, long long s2) {
  long long t1, t2, t3;
  t1 = (m / x) - (m / (x * y));
  t2 = (m / y) - (m / (x * y));
  t3 = m - ((m / x) + (m / y)) + (m / (x * y));
  s1 -= t2;
  s2 -= t1;
  if (max(s1, (long long)0) + max(s2, (long long)0) > t3) return false;
  return true;
}
int main() {
  cin >> a >> b >> x >> y;
  long long s = 0, e = (long long)1000 * 1000 * 1000 * 1000, m;
  while (s < e) {
    m = (s + e) / 2;
    if (chek(m, a, b) == true) {
      javab = m;
      e = m;
    } else
      s = m + 1;
  }
  cout << e << endl;
  return 0;
}
