#include <bits/stdc++.h>
using namespace std;
long long n, m, x, y;
int judge(long long mid) {
  long long t1 = mid / x, t2 = mid / y;
  long long t3 = mid / (x * y);
  long long gx = mid - t1 - t2 + t3;
  long long c1 = n - (t2 - t3), c2 = m - (t1 - t3);
  if (c1 > 0) gx -= c1;
  if (gx < 0) return -1;
  if (c2 > 0) gx -= c2;
  if (gx < 0) return -1;
  return 1;
}
long long erfen(long long l, long long r) {
  long long ans = 0;
  while (l <= r) {
    long long mid = (r + l) / 2;
    if (judge(mid) == 1) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  return ans;
}
int main(int argc, char** argv) {
  while (scanf("%lld %lld %lld %lld", &n, &m, &x, &y) != EOF) {
    long long l = m + n;
    long long r = 2 * m + 2 * n;
    printf("%lld\n", erfen(l, r));
  }
  return 0;
}
