#include <bits/stdc++.h>
using namespace std;
long long int cnt1, cnt2, x, y;
int f(long long int k) {
  long long int f0 = k / x, f1 = k / y, p = x * y;
  long long int f3 = k / p;
  long long int other = k - f0 - f1 + f3;
  f0 == f3;
  f1 -= f3;
  long long int cnt0 = cnt1 - f1, cnt11 = cnt2 - f0;
  if (cnt0 < 0) {
    cnt0 = 0;
  }
  if (cnt11 < 0) {
    cnt11 = 0;
  }
  return (cnt0 + cnt11 <= other);
}
int main() {
  long long int st, ed, mid;
  cin >> cnt1 >> cnt2 >> x >> y;
  st = 1;
  ed = 1e18;
  while (ed - st > 1) {
    mid = (st + ed) >> 1;
    if (f(mid)) {
      ed = mid;
    } else {
      st = mid;
    }
  }
  cout << ed << endl;
  return 0;
}
