#include <bits/stdc++.h>
using namespace std;
int ans, c1, c2, x, y;
int gcd(int a, int b) {
  if (a > b) swap(a, b);
  while (a) {
    b = b % a;
    swap(a, b);
  }
  return b;
}
int check(int m) {
  int g = m / (x * (y / gcd(x, y))), f1 = m / y + g, f2 = m / x + g;
  int tmp = m - m / x - m / y + g;
  if (tmp >= max(0, c1 - f1) + max(0, c2 - f2))
    return 1;
  else
    return 0;
}
int search() {
  int l = 1, m, i, h = 1000000000;
  while (l <= h) {
    m = (l + h) / 2;
    if (check(m))
      h = m - 1;
    else
      l = m + 1;
  }
  for (i = max(h - 5, 1); i <= min(h + 5, 1000000000); i++)
    if (check(i)) return i;
  return 0;
}
int main() {
  scanf("%d%d%d%d", &c1, &c2, &x, &y);
  ans = search();
  printf("%d\n", ans);
}
