#include <bits/stdc++.h>
using namespace std;
void solve() {
  int a, b, x, y;
  cin >> a >> b >> x >> y;
  if (x == y) {
    int k = a + b;
    int nk = k;
    while (1) {
      if (nk - nk / x >= k) {
        break;
      }
      nk += k - (nk - nk / x);
    }
    cout << nk << endl;
    return;
  }
  int na = a;
  while (1) {
    if (na - na / x >= a) {
      break;
    }
    na += a - (na - na / x);
  }
  int nb = na;
  int r = na / x;
  while (1) {
    int k = (nb - na) - nb / y + na / y + r - na / (y * x);
    if (k >= b) {
      break;
    }
    nb += b - k;
    ;
  }
  int o = nb;
  nb = b;
  while (1) {
    if (nb - nb / y >= b) {
      break;
    }
    nb += b - (nb - nb / y);
  }
  na = nb;
  r = nb / y;
  while (1) {
    int k = (na - nb) - na / x + nb / x + r - nb / (y * x);
    if (k >= a) {
      break;
    }
    na += a - k;
    ;
  }
  o = min(o, na);
  cout << o << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
}
