#include <bits/stdc++.h>
using namespace std;
int main() {
  int cnt1, cnt2, x, y, ans, xn, yn;
  cin >> cnt1 >> cnt2 >> x >> y;
  if (x > y) swap(cnt1, cnt2), swap(x, y);
  int l = 1, h = 1000000000, v = 1;
  ans = -1;
  while (l < h) {
    v = (l + h) >> 1;
    xn = v - (v / x);
    yn = (v - (v / y)) - xn;
    if (max(cnt1, cnt2) > max(xn, yn)) {
      l = v + 1;
    } else if (cnt1 == xn && cnt2 == yn) {
      ans = v;
      break;
    } else {
      h = v - 1;
    }
  }
  if (ans == -1) ans = (l + h) >> 1;
  cout << ans << endl;
  return 0;
}
