#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b) {
  long long ans = 1;
  while (b > 0) {
    if (b % 2 != 0) {
      ans = (ans * a) % 1000000007;
    }
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return ans;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t = 1;
  while (t--) {
    int cnt1, cnt2, x, y;
    cin >> cnt1 >> cnt2 >> x >> y;
    long long high = 1e15, low = 1, mid;
    for (int i = 0; i < 1000; i++) {
      mid = (low + high) / 2;
      long long ko = mid - mid / (y * x);
      if (ko < cnt1 + cnt2 || (mid - mid / x < cnt1) || (mid - mid / y < cnt2))
        low = mid;
      else
        high = mid - 1;
      if (high < low) {
        high = low;
        break;
      }
    }
    for (; low; low++) {
      if ((low - low / (x * y) >= cnt1 + cnt2) && (low - low / x >= cnt1) &&
          (low - low / y >= cnt2))
        break;
    }
    cout << low;
  }
  return 0;
}
