#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a == 0)
    return (b);
  else
    return (gcd(b % a, a));
}
long long ct1, ct2, x, y;
long long possible(long long ans) {
  long long r1 = ct1 - (ans / y - ans / (x * y));
  long long r2 = ct2 - (ans / x - ans / (x * y));
  if (r1 < 0) {
    r1 = 0;
  }
  if (r2 < 0) {
    r2 = 0;
  }
  long long remaining_slots = ans - (ans / x + ans / y - ans / (x * y));
  if (remaining_slots >= r1 + r2) {
    return 1;
  } else {
    return 0;
  }
}
int main() {
  cin >> ct1 >> ct2 >> x >> y;
  long long low = 0;
  long long high = (long long)1 << 40;
  long long mid = (low + high) / 2;
  long long res;
  long long k;
  while (1) {
    if (possible(mid) && !possible(mid - 1)) {
      res = mid;
      break;
    }
    if (possible(mid)) {
      high = mid - 1;
    } else {
      low = mid + 1;
    }
    mid = (low + high) / 2;
  }
  cout << res << endl;
  return 0;
}
