#include <bits/stdc++.h>
using namespace std;
int c1, c2, x1, x2;
bool check(int m) {
  int k = m / (x1 * x2), k1 = m / x1, k2 = m / x2;
  return c1 + c2 <= m - k && c1 <= m - k1 && c2 <= m - k2;
}
void solve() {
  int l = 1, r = 2000000000, mid;
  while (l < r) {
    mid = l + ((r - l) >> 1);
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  printf("%d", l);
}
int main() {
  scanf("%d%d%d%d", &c1, &c2, &x1, &x2);
  solve();
  return 0;
}
