#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int f1, f2, p1, p2;
  cin >> f1 >> f2 >> p1 >> p2;
  int lo = f1 + f2, hi = max(f1 * p2, f2 * p2);
  while (lo < hi) {
    int mid = (lo + hi) >> 1;
    if (f1 + f2 <= mid - mid / (p1 * p2) && f1 <= (mid - mid / p1) &&
        f2 <= (mid - mid / p2))
      hi = mid;
    else
      lo = mid + 1;
  }
  cout << lo;
}
