#include <bits/stdc++.h>
using namespace std;
int main() {
  int c1, c2, asal1, asal2;
  scanf("%d%d%d%d", &c1, &c2, &asal1, &asal2);
  long long int mini = c1 + c2 + (c1 + c2) / (asal1 * asal2);
  long long int maxi = 10 * mini;
  long long int i;
  while (mini < maxi) {
    i = (maxi + mini) / 2;
    long long int a1 = i / asal1;
    long long int a2 = i / asal2;
    long long int a1_a2 = i / (asal1 * asal2);
    long long int a1xa2 = a1 + a2 - a1_a2;
    long long int b1_b2 = i - a1xa2;
    long long int ja1 = a1xa2 - a1;
    long long int ja2 = a1xa2 - a2;
    long long int cvp = ja1 + ja2 + b1_b2;
    if (c1 <= ja1 + b1_b2 && c2 <= ja2 + b1_b2 &&
        (c1 - ja1 >= 0 ? c1 - ja1 : 0) + (c2 - ja2 >= 0 ? c2 - ja2 : 0) <=
            b1_b2) {
      maxi = i;
    } else {
      mini = i + 1;
    }
  }
  printf("%I64d", mini);
  getchar();
  getchar();
  getchar();
  getchar();
  getchar();
  getchar();
  return 0;
}
