#include <bits/stdc++.h>
using namespace std;
const long long A = 1000000000LL, N = 10000;
long long p, i, j, x, y, n, m;
int main() {
  cin >> n >> m >> x >> y;
  if (n > 0) {
    m -= n / (x - 1);
    p += x * (n / (x - 1));
    n %= x - 1;
    if (n > 0) {
      p += n;
      n = 0;
    } else
      p--, m++;
  }
  if (m > 0 && p > 0) {
    long long _p = ((p / y) * y) + y;
    m -= (_p - p);
    p = _p;
  }
  if (m > 0) {
    p += y * (m / (y - 1));
    m %= y - 1;
    if (m > 0) {
      p += m;
      m = 0;
    } else
      p--;
  }
  cout << p;
}
