#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long c1, c2, d1, d2;
bool first(long long val) {
  long long x = val / d1;
  long long y = val / d2;
  long long both = d1 * d2;
  both = val / both;
  long long cnt = val - x - y + both;
  long long x1 = x - both;
  long long y1 = y - both;
  long long x2 = c1 - y1;
  long long y2 = c2 - x1;
  return (max(0LL, x2) + max(0LL, y2) <= cnt);
}
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> c1 >> c2 >> d1 >> d2;
  long long l = 0, h = 1e18;
  long long ans;
  while (l <= h) {
    long long mid = (l + h) >> 1;
    if (first(mid)) {
      ans = mid;
      h = mid - 1;
    } else
      l = mid + 1;
  }
  cout << ans;
  return 0;
}
