#include <bits/stdc++.h>
using namespace std;
int cnt1, cnt2, x, y, t;
int gcd(int num1, int num2);
bool check(int num);
int main() {
  scanf("%d%d", &(cnt1), &(cnt2));
  scanf("%d%d", &(x), &(y));
  t = x * y / gcd(x, y);
  check(4);
  int ll = 0, rr = 0xFFFFFFF;
  while (rr > ll) {
    int mid = (ll + rr) >> 1;
    if (check(mid)) {
      rr = mid;
    } else {
      ll = mid + 1;
    }
  }
  printf("%d\n", ll);
  return 0;
}
bool check(int num) {
  int numX = num / x, numY = num / y;
  int numCom = num / t;
  if (max(cnt1 - numY, 0) + max(cnt2 - numX, 0) <= num - numX - numY + numCom) {
    return true;
  } else {
    return false;
  }
}
int gcd(int num1, int num2) {
  int tmp;
  if (num1 < num2) {
    tmp = num1;
    num1 = num2;
    num2 = tmp;
  }
  while (num2 != 0) {
    tmp = num1 % num2;
    num1 = num2;
    num2 = tmp;
  }
  return num1;
}
