#include <bits/stdc++.h>
using namespace std;
long long a, b, x, y;
int main() {
  cin >> a >> b >> x >> y;
  long long l = 2, r = 1e18, mid = (l + r) / 2;
  while (l < r) {
    long long check = mid - ((mid / y) + (mid / x) - (mid / (x * y)));
    mid = (l + r) / 2;
    if ((mid - (mid / x)) >= a && (mid - (mid / y)) >= b && check <= mid)
      r = mid;
    else
      l = mid + 1;
  }
  cout << l;
  return 0;
}
