#include <bits/stdc++.h>
int gcd(int n, int m) {
  if (m <= n && n % m == 0) return m;
  if (n < m)
    return gcd(m, n);
  else
    return gcd(m, n % m);
}
int main() {
  int cnt1, cnt2, x, y, v = 1, lcm;
  scanf("%d%d%d%d", &cnt1, &cnt2, &x, &y);
  lcm = (x * y) / gcd(x, y);
  for (; v <= lcm; v++) {
    if (cnt1 == 0 && cnt2 == 0)
      break;
    else {
      if (cnt1 > cnt2) {
        if (v % x != 0 && cnt1 > 0) {
          cnt1--;
        } else {
          if (v % y != 0 && cnt2 > 0) {
            cnt2--;
          }
        }
      } else {
        if (v % y != 0 && cnt2 > 0) {
          cnt2--;
        } else {
          if (v % x != 0 && cnt1 > 0) {
            cnt1--;
          }
        }
      }
    }
  }
  printf("%d\n", v - 1);
  return 0;
}
