#include <bits/stdc++.h>
using namespace std;
long long int a, b, x, y;
long long int ok(long long int n) {
  long long int oa = n / x;
  long long int ob = n / y;
  long long int oab = n / x / y;
  long long int com = n - oa - ob + oab;
  long long int ca = n - oa;
  long long int cb = n - ob;
  return (ca >= a && cb >= b && ca + cb - com >= a + b);
}
int main() {
  cin >> a >> b >> x >> y;
  long long int l = max(a, b), r = 1e13;
  while (l < r) {
    long long int m = (l + r) >> 1;
    if (!ok(m))
      l = m + 1;
    else
      r = m;
  }
  cout << r << '\n';
  return 0;
}
