#include <bits/stdc++.h>
using namespace std;
long long a, b, x, y, s, e, mid;
long long tx, ty, t, javab = 0;
int main() {
  cin >> a >> b >> x >> y;
  s = 0;
  e = (long long)10000 * 10000 * 100;
  while (s < e) {
    mid = (s + e) / 2;
    tx = mid / x;
    ty = mid / y;
    t = mid - tx - ty;
    if (t + ty >= a) {
      t -= (a - ty);
      if (t + tx >= b) {
        e = mid;
        javab = e;
        continue;
      }
    }
    s = mid + 1;
  }
  cout << javab << endl;
  return 0;
}
