#include <bits/stdc++.h>
int gcd(int a, int b) { return a % b == 0 ? b : gcd(b, a % b); }
int lca(int a, int b) { return a / gcd(a, b) * b; }
int a, b, c, d;
int solve() {
  for (int i = 1, j = 2147483646; i != j;) {
    if (i == j) return i;
    int mid = (i + j) / 2;
    int ansa = mid / c;
    int ansb = mid / d;
    int ansc = mid / lca(c, d);
    if (mid - ansa < a)
      i = mid + 1;
    else if (mid - ansb < b)
      i = mid + 1;
    else if (mid - ansc < a + b)
      i = mid + 1;
    else
      j = mid;
  }
}
int main() {
  scanf("%d%d%d%d", &a, &b, &c, &d);
  printf("%d\n", solve());
  return 0;
}
