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