#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long c1, c2, x, y;
  cin >> c1 >> c2 >> x >> y;
  long long lo = 1, hi = 1e12, mid, in;
  while (lo <= hi) {
    mid = lo + (hi - lo) / 2;
    long long v1 = mid - mid / x;
    long long v2 = mid - mid / y;
    long long c = mid - (mid / x + mid / y - mid / (x * y));
    if (v1 < c1 || v2 < c2 || v1 + v2 - c < c1 + c2)
      lo = mid + 1;
    else
      hi = mid - 1, in = mid;
  }
  cout << in;
  return 0;
}
