#include <bits/stdc++.h>
using namespace std;
int main() {
  int cnt1, cnt2, x, y;
  cin >> cnt1 >> cnt2 >> x >> y;
  int a, b, c, d, e, f, res;
  a = cnt1 / (x - 1);
  b = cnt1 % (x - 1);
  if (b != 0)
    res = a * x + b;
  else
    res = a * x - 1;
  if (res >= x) cnt2 = cnt2 - a;
  if (cnt2 <= 0)
    cout << res << endl;
  else {
    c = res / y;
    d = (c + 1) * y - res - 1;
    if (cnt2 <= d)
      cout << res + cnt2 << endl;
    else {
      cnt2 -= d;
      a = cnt2 / (y - 1);
      b = cnt2 % (y - 1);
      if (b == 0)
        res = res + d + a * y - 1;
      else
        res = res + d + a * y + b;
      cout << res << endl;
    }
  }
  return 0;
}
