#include <bits/stdc++.h>
using namespace std;
int GCD(int a, int b) {
  while (a > 0 && b > 0) {
    if (a >= b) {
      a %= b;
    } else {
      b %= a;
    }
  }
  if (a > 0) {
    return a;
  } else {
    return b;
  }
}
void Solve() {
  int cnt1, cnt2, x, y;
  cin >> cnt1 >> cnt2 >> x >> y;
  int out = 2000000000;
  int g = GCD(x, y);
  for (int i = 0; i < 2; ++i) {
    swap(x, y);
    swap(cnt1, cnt2);
    int k1 = cnt1 / (x - 1);
    int l1 = cnt1 % (x - 1);
    int num1 = k1 * x;
    if (l1 > 0) {
      num1 += l1;
    } else {
      num1 -= 1;
    }
    int p = x / g;
    int mcnt2 = max(cnt2 - (k1 - (k1 / p)), 0);
    if (mcnt2 == 0) {
      out = min(out, num1);
      continue;
    }
    int k2 = mcnt2 / (y - 1);
    int l2 = mcnt2 % (y - 1);
    num1 += k2 * y;
    p = num1 % y;
    int rem = y - 1 - p;
    if (rem == 0) {
      out = min(out, num1);
    }
    num1 += rem + 1;
    l2 -= rem;
    num1 += l2 - 1;
    out = min(out, num1);
  }
  cout << out << endl;
  return;
  ;
}
int main() {
  Solve();
  return 0;
}
