#include <bits/stdc++.h>
using namespace std;
int main() {
  int cnt1, cnt2, x, y, temp;
  scanf("%d%d%d%d", &cnt1, &cnt2, &x, &y);
  int l = 0, r = 2147483647;
  while (l < r) {
    temp = (long long)l + r >> 1;
    if (temp - temp / x / y >= (cnt1 + cnt2) && temp - temp / x >= cnt1 &&
        temp - temp / y >= cnt2)
      r = temp;
    else
      l = temp + 1;
  }
  printf("%d\n", l);
  return 0;
}
