#include <bits/stdc++.h>
using namespace std;
int ri() {
  int r;
  cin >> r;
  return r;
}
size_t rsz() {
  size_t r;
  cin >> r;
  return r;
}
unsigned int rui() {
  unsigned int r;
  cin >> r;
  return r;
}
long long rl() {
  long long r;
  cin >> r;
  return r;
}
unsigned long long rul() {
  unsigned long long r;
  cin >> r;
  return r;
}
double rd() {
  double r;
  cin >> r;
  return r;
}
string rss() {
  string r;
  cin >> r;
  return r;
}
string rs() {
  string r;
  getline(cin, r);
  return r;
}
vector<string> rvs(int n) {
  assert(n);
  vector<string> r;
  for (int i = 0; i < n; ++i) {
    string s = rs();
    while (s.empty()) s = rs();
    r.push_back(s);
  }
  return r;
}
vector<int> rvi(int n) {
  assert(n);
  vector<int> r;
  for (int i = 0; i < n; ++i) r.push_back(ri());
  return r;
}
vector<unsigned int> rvui(int n) {
  assert(n);
  vector<unsigned int> r;
  for (int i = 0; i < n; ++i) r.push_back(rui());
  return r;
}
vector<long long> rvl(int n) {
  assert(n);
  vector<long long> r;
  for (int i = 0; i < n; ++i) r.push_back(rl());
  return r;
}
vector<unsigned long long> rvul(int n) {
  assert(n);
  vector<unsigned long long> r;
  for (int i = 0; i < n; ++i) r.push_back(rul());
  return r;
}
vector<double> rvd(int n) {
  assert(n);
  vector<double> r;
  for (int i = 0; i < n; ++i) r.push_back(rd());
  return r;
}
unsigned long long gcd(unsigned long long a, unsigned long long b) {
  if (!a) return b;
  if (a < b) swap(a, b);
  return gcd(a % b, b);
}
unsigned long long lcm(unsigned long long a, unsigned long long b) {
  return a * b / gcd(a, b);
}
int main(int argc, const char* argv[]) {
  auto cnt1 = rul(), cnt2 = rul(), x = rul(), y = rul();
  auto skip = lcm(x, y);
  auto req = cnt1 + cnt2;
  unsigned long long l = 1, h = numeric_limits<unsigned long long>::max();
  auto last = 0;
  while (l <= h) {
    auto m = l + (h - l) / 2;
    auto t1 = m / x - m / skip;
    auto t2 = m / y - m / skip;
    auto comm = m + m / skip - m / x - m / y;
    auto c1 = t2;
    if (c1 < cnt1 && comm >= (cnt1 - c1)) {
      comm -= cnt1 - c1;
      c1 = cnt1;
    }
    auto c2 = t1 + comm;
    if (c1 == cnt1 && c2 == cnt2) {
      last = m;
      break;
    }
    if (c1 < cnt1 || c2 < cnt2) {
      l = m + 1;
    } else {
      last = m;
      h = m - 1;
    }
  }
  cout << (last % skip == 0 ? (last - 1) : last) << endl;
  return 0;
}
