#include <bits/stdc++.h>
using namespace std;
int main() {
  int cnt1, cnt2, x, y;
  cin >> cnt1 >> cnt2 >> x >> y;
  int lo = 1, hi = 0x7FFFFFFF, mid;
  while (lo < hi) {
    mid = lo + (hi - lo) / 2;
    int remx = mid - (mid / x);
    int remy = mid - (mid / y);
    int totrem = mid - (mid / (x * y));
    if (cnt1 <= remx && cnt2 <= remy && cnt1 + cnt2 <= totrem)
      hi = mid;
    else
      lo = mid + 1;
  }
  cout << hi << endl;
  return 0;
}
