#include <bits/stdc++.h>
using namespace std;
const double error = 1e-15;
const double pi = 2 * acos(0);
const int maxn = (int)1e5 + 10;
const int mod = (int)1e9;
int main() {
  long long int i, j, n, m, x, y, p, a;
  cin >> n >> m >> x >> y;
  i = n;
  while (1) {
    p = i / x;
    if (i - p >= n) {
      a = i / x - i / (x * y);
      break;
    } else {
      i = n + p;
    }
  }
  if (m <= a) {
    cout << i << endl;
    return 0;
  }
  m = m - a;
  do {
    i++;
    m--;
  } while (m > 0 && i % y != 0);
  if (m == 0) {
    cout << i << endl;
    return 0;
  }
  j = m;
  while (1) {
    p = j / y;
    if (j - p >= m) {
      break;
    } else {
      j = m + p;
    }
  }
  cout << (i + j) << endl;
  return 0;
}
