#include <bits/stdc++.h>
using namespace std;
int cnt1, cnt2, x, y;
bool can(long long v) {
  long long a_not_want = v / x;
  long long b_not_want = v / y;
  long long ab_not_want = v / (x * y);
  long long a_want_left = cnt1 - (b_not_want - ab_not_want);
  long long b_want_left = cnt2 - (a_not_want - ab_not_want);
  long long ab_want_left = max(0LL, a_want_left) + max(0LL, b_want_left);
  long long all_left = v - (a_not_want + b_not_want - ab_not_want);
  return all_left >= ab_want_left;
}
int main() {
  scanf("%d%d%d%d", &cnt1, &cnt2, &x, &y);
  long long l = 1, r = 1e15;
  while (l < r) {
    long long m = (l + r) >> 1;
    if (can(m)) {
      r = m;
    } else {
      l = m + 1;
    }
  }
  printf("%I64d\n", r);
  return 0;
}
