#include <bits/stdc++.h>
int main() {
  unsigned c1 = 0, c2 = 0, x = 0, y = 0;
  std::cin >> c1 >> c2 >> x >> y;
  ;
  ;
  ;
  ;
  unsigned v = c1 + c2;
  while (1) {
    ;
    ;
    unsigned mul_xy = v / (x * y);
    unsigned mul_x = v / x;
    unsigned mul_y = v / y;
    ;
    ;
    ;
    long set_a = mul_y - mul_xy;
    long set_b = mul_x - mul_xy;
    long set_either = v - mul_xy - set_a - set_b;
    ;
    ;
    ;
    ;
    if (c1 > set_a) set_either -= c1 - set_a;
    if (c2 > set_b) set_either -= c2 - set_b;
    ;
    if (set_either >= 0) {
      ;
      ;
      std::cout << v << "\n";
      return 0;
    } else
      v += -set_either;
  }
  while (1) {
    long set_either = 0;
    long set_neither = 0;
    long set_a = 0;
    long set_b = 0;
    for (unsigned i = 1; i <= v; ++i) {
      if (i % x && i % y)
        ++set_either;
      else if (i % x == 0 && i % y == 0)
        ++set_neither;
      else if (i % x == 0)
        ++set_b;
      else
        ++set_a;
    };
    ;
    ;
    ;
    ;
    if (c1 > set_a) set_either -= c1 - set_a;
    if (c2 > set_b) set_either -= c2 - set_b;
    ;
    if (set_either >= 0) {
      ;
      ;
      std::cout << v << "\n";
      return 0;
    } else
      v += -set_either;
  }
}
