#include <bits/stdc++.h>
using namespace std;
long long int c1, c2, x, y;
long long int comp(long long int t) {
  long long int r1 = t / x, r2 = t / y, l = x * y, both = t / l;
  long long int left = t - r1 - r2 + both;
  r1 = r1 - both;
  r2 = r2 - both;
  long long int left1 = c1 - r2, left2 = c2 - r1;
  if (left1 < 0) left1 = 0;
  if (left2 < 0) left2 = 0;
  if (left1 + left2 <= left)
    return 1;
  else
    return 0;
}
long long int bs() {
  long long int st = 0, en = 1e18;
  while (en - st > 1) {
    long long int mid = (st + en) / 2;
    if (comp(mid))
      en = mid;
    else
      st = mid;
  }
  return en;
}
int main() {
  cin >> c1 >> c2 >> x >> y;
  cout << bs();
}
