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