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