#include <bits/stdc++.h>
int main() {
  int i, j, k, z, l, a, b, x, y, q, r, s = 0, ss, an, an1;
  scanf("%d%d%d%d", &a, &b, &x, &y);
  z = x - 1;
  r = a % z;
  q = a / z;
  if (r == 0) r = -1;
  s = x * (q) + r;
  ss = x * b;
  if (s > ss)
    an1 = s;
  else
    an1 = ss;
  z = y - 1;
  r = b % z;
  q = b / z;
  if (r == 0) r = -1;
  s = y * (q) + r;
  ss = y * a;
  if (s > ss)
    an = s;
  else
    an = ss;
  if (an1 > an) an1 = an;
  printf("%d\n", an1);
  return 0;
}
