#include <bits/stdc++.h>
using namespace std;
template <typename T>
void show(const T& v) {
  cerr << v << ' ';
}
template <typename T1, typename... T2>
void show(const T1& first, const T2&... rest) {
  show(first);
  show(rest...);
}
template <typename F, typename S>
ostream& operator<<(ostream& os, const pair<F, S>& p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "{";
  typename vector<T>::const_iterator it;
  for (it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
  os << "[";
  typename set<T>::const_iterator it;
  for (it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}
template <typename F, typename S>
ostream& operator<<(ostream& os, const map<F, S>& v) {
  os << "[";
  typename map<F, S>::const_iterator it;
  for (it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << it->first << " = " << it->second;
  }
  return os << "]";
}
long long cnt1, cnt2, x, y;
bool func(long long n) {
  long long f1 = (n / x), f2 = (n / y);
  f1 -= (n / (x * y)), f2 -= (n / (x * y));
  long long v1 = max(0LL, cnt1 - f2);
  long long v2 = max(0LL, cnt2 - f1);
  long long extra = n - (n / x) - (n / y) + (n / (x * y));
  return (v1 + v2) <= extra;
}
void solve() {
  cin >> cnt1 >> cnt2 >> x >> y;
  long long lo = 1, hi = 1e15 + 5LL;
  long long ans = 0;
  while (lo <= hi) {
    long long mid = lo + (hi - lo) / 2LL;
    if (func(mid)) {
      ans = mid;
      hi = mid - 1LL;
    } else
      lo = mid + 1LL;
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int t = 1, cs = 0;
  while (t--) {
    solve();
  }
  return 0;
}
