#include <bits/stdc++.h>
int gcd(int a, int b) {
  if (a == 0 && b == 0) return -1;
  if (b == 0) return a;
  return gcd(b, a % b);
}
int ceil(int a, int b) {
  if (a % b == 0)
    return a / b;
  else
    return a / b + 1;
}
int main() {
  int cnt1, cnt2, x, y;
  int cnt_min, tmp, cnt_gcd, max, start;
  scanf("%d %d %d %d", &cnt1, &cnt2, &x, &y);
  if ((x * cnt1 < y * cnt2) || (x * cnt1 == y * cnt2 && x > y)) {
    tmp = x;
    x = y;
    y = tmp;
    tmp = cnt1;
    cnt1 = cnt2;
    cnt2 = tmp;
  }
  cnt_gcd = gcd(x, y);
  max = x * y / cnt_gcd;
  cnt_min = cnt1 + ceil(cnt1, x - 1) - 1;
  tmp = cnt_min / x - cnt_min / max;
  if (tmp >= cnt2) {
    printf("%d", cnt_min);
  } else {
    cnt2 -= tmp;
    tmp = y - 1 - cnt_min % y;
    if (tmp >= cnt2) {
      printf("%d", cnt_min + tmp);
    } else {
      cnt2 -= tmp;
      start = (cnt_min / y + 1) * y;
      tmp = cnt2 + ceil(cnt2, y - 1) - 1;
      printf("%d", start + tmp);
    }
  }
  return 0;
}
