#include <bits/stdc++.h>
using namespace std;
int ct1, ct2, x, y;
bool eleg(long long int v) {
  long long divy = v / y;
  long long divx = v / x;
  long long both = v - divy - divx;
  long long hx = (0 > (ct1 - divy) ? 0 : (ct1 - divy));
  long long hy = ((ct2 > divx) ? (ct2 - divx) : 0);
  if (hx + hy <= both) {
    return true;
  } else {
    return false;
  }
}
int main() {
  cin >> ct1 >> ct2 >> x >> y;
  long long l, u, m;
  l = 1;
  u = 1000000000000;
  while (l < u) {
    m = (l + u) / 2;
    if (eleg(m)) {
      u = m;
    } else {
      l = m + 1;
    }
  }
  cout << l << endl;
  return 0;
}
