#include <bits/stdc++.h>
using namespace std;
int n1, n2, p1, p2;
int main() {
  scanf("%d%d%d%d", &n1, &n2, &p1, &p2);
  long long l = n1 + n2, r = 1e18, mid;
  long long a, b, c;
  while (l != r) {
    mid = (l + r) / 2;
    a = mid / p1;
    b = mid / p2;
    c = mid / (p1 * p2);
    if (max(0ll, n1 - b + c) + max(0ll, n2 - a + c) <= mid - a - b + c) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }
  printf("%l64d", r);
  fclose(stdin);
  fclose(stdout);
  return 0;
}
